iamacarpet / go-win64api Goto Github PK
View Code? Open in Web Editor NEWWindows API wrappers for Go - useful for SysOps
License: MIT License
Windows API wrappers for Go - useful for SysOps
License: MIT License
Due to misuse of unsafe pointers, after a while go process crashes due to memory corruption.
Here is the output when memory corruption happens:
fatal error: unexpected signal during runtime execution
[signal 0xc0000005 code=0x1 addr=0xc0008cb910 pc=0xa4e77a]
After solving the issue, I will try to send a pull request.
As title, user programs like VS Code installed with user installer won't be in the list.
This project is awesome.I used it on my work. thanks.
Is there a way to RunAs another windows user like this?
https://www.autoitscript.com/autoit3/docs/functions/RunAs.htm
At the moment, our app using this library runs as a system service.
As such, any processes started end up running in the services virtual desktop, so aren't visible to the user & they can't interact with them.
To get around this, we currently have to use a combination of PowerShell & psexec:-
It would be great to implement this natively, so we can just specify it as an option when starting a process.
There's an example of it in C++ at https://github.com/poweradminllc/PAExec , although I haven't tried the application out to be able to say if it works or not.
The title says it all https://github.com/iamacarpet/go-win64api/blob/master/firewall.go#L657
Hello.
Can you tell me how to implement a list of installed programs from the registry branch of the current user?
The InstalledSoftwareList() function specifies registry.OpenKey(registry.LOCAL_MACHINE, ...
how to add registry.CURRENT_USER to additionally get the list of programs from the registry of the user?
Any information would be appreciated.
For local users, is there a way to get a user's SID? I don't see anything in the codebase, but I thought I'd ask first in case I was stupid.
We rely on various functions in the winapi package for local user account management.
Our tooling relies on valid JSON output, but there's a print statement in users.go that can cause breakage.
The GetConversionStatus method provides additional useful information about the status of a drive while in the process of being encrypted.
https://docs.microsoft.com/en-us/windows/win32/secprov/getconversionstatus-win32-encryptablevolume
Hello,
This commit:
d00ffa8#diff-6a51b0579e670aadd8529ea38ef8d456cda3d399be6f10adea33137a77f81341R14-R21
appears to have broken support for Windows 7. I realize windows 7 is old and not particularly supported, but my app has been working just fine until this commit. I wonder if there's a way to work around this, or a fix you can put it to allow these things to be 'skipped' on Windows 7?
panic: Failed to find NetCreateProvisioningPackage procedure in Netapi32.dll: Th
e specified procedure could not be found.
goroutine 1 [running]:
syscall.(*DLL).MustFindProc(...)
syscall/dll_windows.go:150
github.com/iamacarpet/go-win64api.init()
github.com/iamacarpet/[email protected]/pro
visioning.go:18 +0x16b7
Thank you very much!
-david
Groups on non-english computers, are named according to the device's language, and as such there generally isn't any group named "User". for example, on my french work computer, the corresponding group is called "Utilisateurs".
Thus it is impossible to add a user to the "User" group, and if you try it results in the error code "unable to process. 2220" as one would expect.
this problem is also found in the functions setAdmin and RevokeAdmin.
i have just started using this lib and i therefore do not know how prevalent similar issues may or may not be.
while i have yet to find a solution, i am looking into using SIDs, as mentioned in this stackoverflow thread
why i add user fail . the error message is Unable to process. 5
As a starting point to implementing RunAs functionality, we'll need to be able to create tokens with ZwCreateToken
This is an apparently undocumented API that allows you to execute as a user without their full credentials.
This library normally runs (for us) as NT AUTH\SYSTEM, so permissions shouldn't be a problem.
A good example, I'm told, is "RunAsEx" on CodeProject.
This will then allow "CreateProcessAsUser" with that token.
Hello,
I tried to compile all examples provided but two of them does not compile.
The Windows Update Status example failed to compile with this error :
./update.go:9:21: cannot assign 2 values to 3 variables
Its this line : upd, nupd, err := wapi.UpdatesPending()
The List Services example failed to compile with this error :
runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"
For your information :
go version go1.9.4 linux/amd64
GOOS=windows GOARCH=amd64 go build -o update.exe update.go
GOOS=windows GOARCH=amd64 go build -o service.exe service.go
The first problem seems to be that UpdatesPending() had changed but the example was not updated.
Bests regards, Olivier.
When using go-win64api
in an application released using goreleaser, I am getting the following error:
error=failed to build for windows_arm64: exit status 1: github.com/iamacarpet/go-win64api: build constraints exclude all Go files in /home/runner/go/pkg/mod/github.com/iamacarpet/[email protected]
Is it possible to use this wrapping api to force the some user to logout and ban to login. and enable or active it again.
like the OG internet cafe to control the computer usage.
It looks like commit f838a77 inadvertently broke the bitlockerConversionStatus by changing the types from int32 to uint32. Our dependent code started returning the "unable to get conversion status while getting BitLocker info; the volume is locked" error. Further investigation suggested this was due to !ok triggering on the type conversion, rather than on the value itself.
It should be possible to confirm this by checking the behavior with reflect.TypeOf:
fmt.Printf("Result type: %s", reflect.TypeOf(statusResultRaw.Value()))
https://github.com/iamacarpet/go-win64api/blob/master/software.go#L42 uses registry.OpenKey
open a registry key, but never close it.
Hello,
I have used this package a ton a really love it. I would love to help expand it but I do not really see how your code works. That being said if you have a feature request area I would love to ask for a way to query user groups within the system. A way to find out what groups a user belongs to and what users are contained within specific user groups. Thanks a ton for all of the great work on this so far.
Lots of application installers don't populate the InstallDate registry value. In these cases 'Add/Remove Programs' apparently substitutes the last modified date for that application's registry key. Better than nothing..
It looks like that could be pretty trivial to implement - https://pkg.go.dev/golang.org/x/sys/windows/registry#KeyInfo.ModTime - so hopefully you'll consider adding this?
Thanks.
I noticed while reading the code within winupdate.go
that there are two private functions. One for listing updates and another for update history. It would be quite useful to be able to access this type of information through some public functions.
I don't think that it would be difficult to add a public version of listUpdates()
that provided the output using the struct already existing in the shared folder. updateHistory()
based on my review could potentially just be made public with no changes.
I would ask that there is some consideration for making the information that those two functions provide accessible outside UpdatesPending()
if possible.
Its also possible that I am misunderstanding the code in some way, so if it is already possible to access this data through UpdatesPending()
please advise me so I can attempt to access this information for a project of mine.
Hi @iamacarpet!
Yesterday I was looking at go-win64api API, and it may be good to think about current state. :-) I would like to introduce API revamp and a lot of braking changes. I think go modules (or generally releasing versions) could help with compatibility. I have no experiences with that so far, but maybe You have, or I will figure out how to do this correctly if You would be interested in doing this.
If You consider aiming for v2 of this library I would like to see following changes:
ListLocalGroups
would become LocalGroupsList
(or GroupList
)InstalledSoftwareList
would become SoftwareListInstalled
IsLocalUserAdmin
would be UserIsLocalAdmin
IsDomainUserAdmin
would be UserIsDomainAdmin
AddGroupMembership
would be GroupAdd
ChangePassword
would be UserPassword
LocalGroup*
become just Group*
. It is unlikely we will be manipulating domain groups, so maybe words Local
vs Domain
should be used only when we have functions to work with both?This would make v2 completely incompatible with version 1, but maybe with easier to use and cleaner API?
I do not want to force this change if You feel it would not be good for this library, and will completely understand if You do not wont to go this way. It is just idea and I may be wrong, but if You like this I am here to help and I can do most of mentioned changes, I would only need critical eye to watch me carefully. ;-)
Hey @iamacarpet.
I'm trying to use a part of a package to control windows firewall.
It works well, but it doesn't release memory. For example, running functions in a loop will cause continuous incremental memory usage.
Looking at the library, it seems that this topic is taken care of(functions like firewallAPIRelease, firewallRulesEnumRealease).
Here's an example of code that replicates an issue.
package main
import (
"fmt"
winapi "github.com/kumako/go-win64api"
"time"
)
func main(){
var first string
for 1>0 {
fmt.Scanln(&first)
if first == "run"{
firewallTest()
}
}
}
func firewallTest(){
//get the list of the rules
ruleList, _ := winapi.FirewallRulesGet()
//delete them one by one using their names
for _, eachRule := range ruleList {
ruleName := eachRule.Name
if ruleName != ""{
winapi.FirewallRuleDelete(ruleName)
}
}
//wait for 30 second
time.Sleep(30 * time.Second)
//add them back, one by one, from the list
for _, eachRule := range ruleList{
winapi.FirewallRuleAddAdvanced(eachRule)
}
}
Line 130 in 532dbaa
Cannot use 'nsec' (type uint64) as type int64
It seems "return time.Unix(0, nsec)", time.Unix doesn't accept uint64.
As part of the LocalUser
struct, there is a uint32 called BadPasswordCount
. What exactly is this number?
Examples:
Line 208 in 8cbc936
Line 432 in 8cbc936
Line 437 in 8cbc936
This results in error 2220:
2220 | The group name could not be found. | NERR_GroupNotFound
Maybe change the group names to be variables?
Hi, I'm trying to change a user password but I'm having this error:
Unable to process: status=2245 error=4294967295
I google it and there's no information about this error numbers. Is there a chance to have a list of go-win64api error numbers list?
Thanks!
Hello !
I try to use "Windows Update Status" on Windows 2016 x64 and get error:
Error fetching data... Unable to process update history entry: 36. Error while getting property Title from Windows Update history. Exception occurred.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x107439]
Everything works on other versions of Windows (10, 2012, 2012 R2)
Dear All,
I am new to golang and still learning things. Could you please let me know, if there is a way we can check if the network connection is metered or not in goLang? Any Windows API will help to check this issue?
Any suggestions are appreciated.
Hi @iamacarpet!
I love this library and use it in some of my tools. I am currently working on more firewall related functions and will PR soon.
Currently we have:
FirewallRuleCreate(name, description, group, appPath, port string, protocol uint) (bool, error)
I am not sure, that this function is well defined. I am trying to add simple rule for some port, let say:
added, err := wapi.FirewallRuleCreate(
"VNC Server Port 5900",
"Common VNC Server port 5900.",
"",
"",
"5900",
wapi.NET_FW_IP_PROTOCOL_TCP,
)
Result is: Error adding Rule: Exception occurred.
. Reason is, that IMO it is impossible to add rule not related to specific program.
I would like to create something like this:
FirewallRuleAdd(name, description, group, port string, protocol uint, profile int) (bool, error)
FirewallRuleDelete(name) (bool, error)
FirewallApplicationRuleAdd(name, description, group, appPath string, profile int) (bool, error)
FirewallApplicationRuleDelete(name string) (bool, error)
FirewallGroupEnable(name string, profile int) error
FirewallGroupDisable(name string, profile int) error
etc.
What do You think about that?
I would not touch FirewallRuleCreate
, so no breaking change would be introduced.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.