Code Monkey home page Code Monkey logo

go-win64api's Introduction

Hi there 👋

go-win64api's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-win64api's Issues

Support Windows running on Arm architecture

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]

Feature Request: Provide Additional Win Update Functionality

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.

some examples does not compile

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.

Create Session Tokens with ZwCreateToken

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.

bitlockerConversionStatus broken by type change

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()))

SID for users.

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.

Start Process on Another Desktop

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:-

  • First to query the virtual desktop ID of the current user (PowerShell)
  • Secondly, to start the process in the context of that virtual desktop, so it is visible (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.

Memory leak while using firewall.go

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)
    }
}

Is it possible to use this wrapping api

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.

Hardcoded english group names don't work on non-english Windows versions

Examples:

return AddGroupMembership(opts.Username, "Users")

return AddGroupMembership(username, "Administrators")

return RemoveGroupMembership(username, "Administrators")

This results in error 2220:

2220 | The group name could not be found. | NERR_GroupNotFound

Maybe change the group names to be variables?

Feature Request: Groups Support For Users

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.

Memory corruption and possible memory leak due to ListLoggedInUsers()

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.

Hardcoding "Users" in UserAddEx makes the function fail on non-english devices

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

Windows Update check failed.

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)

software.go: InstalledSoftwareList() from registry.CURRENT_USER

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.

Aiming for v2?

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:

  • IDE autocomplete and user memory friendliness:
    All functions should start with topic name so for example:
    ListLocalGroups would become LocalGroupsList (or GroupList)
    InstalledSoftwareList would become SoftwareListInstalled
  • Better function names in general (very subjective):
    • IsLocalUserAdmin would be UserIsLocalAdmin
    • IsDomainUserAdmin would be UserIsDomainAdmin
    • AddGroupMembership would be GroupAdd
    • ChangePassword would be UserPassword
  • Other changes which could make API nicer. F. e. should 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?
  • Maybe think about function parameters and returned values? At first glance they are ok IMO.
  • Better godoc documentation - good package description (most of current readme) ,more comments, move examples to documentation, add godoc badge to readme, shorten readme.

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. ;-)

Windows 7 broken with recent commit.

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
  • 64 bit Windows 7 Pro with SP1

Thank you very much!
-david

Error number list

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!

Firewall functions

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.