mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 03:40:08 +00:00
Add support to core:windows to add/delete users.
main :: proc() {
using fmt;
using windows;
username := "testuser";
password := "testpass";
ok := add_user("", username, password);
fmt.printf("add_user: %v\n", ok);
pi := windows.PROCESS_INFORMATION{};
ok2, path := windows.add_user_profile(username);
fmt.printf("add_user_profile: %v, %v\n", ok2, path);
ok3 := windows.delete_user_profile(username);
fmt.printf("delete_user_profile: %v\n", ok3);
ok4 := windows.delete_user("", username);
fmt.printf("delete_user: %v\n", ok4);
// Has optional bool to not wait on the process before returning.
b := run_as_user(username, password, "C:\\Repro\\repro.exe", "Hellope!", &pi);
fmt.printf("run_as_user: %v %v\n", b, pi);
}
This commit is contained in:
@@ -10,3 +10,57 @@ foreign advapi32 {
|
||||
DesiredAccess: DWORD,
|
||||
TokenHandle: ^HANDLE) -> BOOL ---
|
||||
}
|
||||
|
||||
// Necessary to create a token to impersonate a user with for CreateProcessAsUser
|
||||
@(default_calling_convention="stdcall")
|
||||
foreign advapi32 {
|
||||
LogonUserW :: proc(
|
||||
lpszUsername: LPCWSTR,
|
||||
lpszDomain: LPCWSTR,
|
||||
lpszPassword: LPCWSTR,
|
||||
dwLogonType: Logon32_Type,
|
||||
dwLogonProvider: Logon32_Provider,
|
||||
phToken: ^HANDLE,
|
||||
) -> BOOL ---
|
||||
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-lookupaccountnamew
|
||||
// To look up the SID to use with DeleteProfileW.
|
||||
LookupAccountNameW :: proc(
|
||||
lpSystemName: wstring,
|
||||
lpAccountName: wstring,
|
||||
Sid: ^SID,
|
||||
cbSid: ^DWORD,
|
||||
ReferencedDomainName: wstring,
|
||||
cchReferencedDomainName: ^DWORD,
|
||||
peUse: ^SID_TYPE,
|
||||
) -> BOOL ---
|
||||
|
||||
CreateProcessWithLogonW :: proc(
|
||||
lpUsername: wstring,
|
||||
lpDomain: wstring,
|
||||
lpPassword: wstring,
|
||||
dwLogonFlags: DWORD,
|
||||
lpApplicationName: wstring,
|
||||
lpCommandLine: wstring,
|
||||
dwCreationFlags: DWORD,
|
||||
lpEnvironment: LPVOID,
|
||||
lpCurrentDirectory: wstring,
|
||||
lpStartupInfo: LPSTARTUPINFO,
|
||||
lpProcessInformation: LPPROCESS_INFORMATION,
|
||||
) -> BOOL ---
|
||||
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessasuserw
|
||||
CreateProcessAsUserW :: proc(
|
||||
hToken: HANDLE,
|
||||
lpApplicationName: wstring,
|
||||
lpCommandLine: wstring,
|
||||
lpProcessAttributes: LPSECURITY_ATTRIBUTES,
|
||||
lpThreadAttributes: LPSECURITY_ATTRIBUTES,
|
||||
bInheritHandles: BOOL,
|
||||
dwCreationFlags: DWORD,
|
||||
lpEnvironment: LPVOID,
|
||||
lpCurrentDirectory: wstring,
|
||||
lpStartupInfo: LPSTARTUPINFO,
|
||||
lpProcessInformation: LPPROCESS_INFORMATION,
|
||||
) -> BOOL ---;
|
||||
}
|
||||
Reference in New Issue
Block a user