C# Class Abstractions.WindowsApi.pInvokes

Show file Open project: MutonUfoAI/pgina Class Usage Examples

Public Methods

Method Description
CloseHandle ( IntPtr handle ) : bool
CreateUserProfileDir ( IntPtr hToken, string username ) : string

calls API CreateProfile an empty string on error a null string on already exists a string on success

DeleteProfile ( System.Security.Principal.SecurityIdentifier sid ) : bool
DisconnectNetworkDrive ( string remoteUNC ) : System.Boolean

disconnecting an UNC share

DomainMember ( string domain ) : bool

query if the domain is part of a domain tree in which the local computer is a member of

GetCredentials ( string caption, string message ) : NetworkCredential
GetFreeShareSpace ( string share ) : long[]

Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread. based on http://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx

GetInteractiveUserList ( ) : List
GetMachineDomainMembership ( ) : string

get local machine domain membership as NETBIOS name

GetMachineDomainMembershipEX ( ) : string

get local machine domain membership as DNS name

GetOrSetUserProfileDir ( string username, string domain, string password ) : string

get or create user profile directory only if the ProfileList regkey is not of SID.bak (Abstractions.User.FixProfileList) an empty or null string means error

GetRegistryLocation ( structenums location ) : RegistryKey

get RegistryKey from structenums.RegistryLocation

GetSessionContext ( ) : List>.Dictionary

returns a Dictionary of SessionID Keys and a List of usernames based on context in which a program is running. a program running as administrator will add administrator to the list

GetSessionContext ( int sessionID ) : List

return username based on context in which a program is running. a program running as administrator will add administrator to the list session ID -1 retuns all sessions instead of a specific one

GetSessionContextParser ( int sessionID, Dictionary contextALL ) : List

return username based on context in which a program is running. a program running as administrator will add administrator to the list session ID -1 retuns all sessions instead of a specific one

GetSessionId ( ) : int
GetUserDomain ( int sessionId ) : string
GetUserName ( int sessionId ) : string
GetUserProfileDir ( IntPtr hToken ) : string

returns userprofile based on GetUserProfileDirectory only if the ProfileList regkey is not of SID.bak (Abstractions.User.FixProfileList) empty string means error

GetUserProfilePath ( IntPtr hToken ) : string

returns userprofile based on SHGetFolderPath only if the profile realy exists and the ProfileList regkey is not of SID.bak (Abstractions.User.FixProfileList) empty string means error

GetUserToken ( string username, string domain, string password ) : IntPtr

Create a handle to the user token make sure to close the handle!!!

IsSessionLoggedOFF ( int session ) : bool
LastError ( ) : string

returns GetLastWin32Error as string

LastError ( int error ) : string

returns GetLastWin32Error as string

LogoffSession ( int sessionId ) : bool
MapNetworkDrive ( string remoteUNC, string username, string password ) : Boolean

connect to a remote computer based on http://social.msdn.microsoft.com/Forums/et-EE/netfxbcl/thread/58159e0e-aa45-4d46-a128-596c3d23ff5c

MapNetworkDrive ( string remoteUNC, string username, string password, bool promptUser ) : Boolean

connect to a remote computer based on http://social.msdn.microsoft.com/Forums/et-EE/netfxbcl/thread/58159e0e-aa45-4d46-a128-596c3d23ff5c

MapNetworkDrive ( string unc, string drive, string user, string password ) : int

Map a network drive.

RegistryCloseKey ( UIntPtr hKey ) : Boolean
RegistryCopyKey ( UIntPtr hKey_src, string SubKey, UIntPtr hKey_dst ) : Boolean
RegistryCreateKey ( structenums RootKey, string SubKey ) : UIntPtr
RegistryDeleteTree ( structenums RootKey, string SubKey ) : Boolean
RegistryLoad ( structenums where, string name, string file ) : Boolean

load a regfile at hklm or hku

RegistryOpenKey ( structenums RootKey, string SubKey ) : UIntPtr
RegistryUnLoad ( structenums where, string name ) : Boolean

unload regfile from regkey

SendMessageToUser ( int sessionID, string title, string message ) : Boolean

send a messagebox to a session

SetPreshutdownTimeout ( SafeHandle handle, structenums &myServiceStatus ) : bool
SetServiceStopped ( IntPtr handle, structenums &myServiceStatus ) : bool
ShutdownPending ( IntPtr handle, structenums &myServiceStatus, TimeSpan wait ) : bool
StartProcessInSession ( int sessionId, string cmdLine ) : Process
StartProcessInSessionWait ( int sessionId, string cmdLine ) : bool
StartProcessWithToken ( IntPtr token, string cmdLine ) : Process
StartUserProcessInSession ( int sessionId, string cmdLine ) : bool
StartUserProcessInSessionWait ( int sessionId, string cmdLine ) : bool
UserADD ( string username, string password, string comment ) : Boolean

add user to the local system based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD

UserChangePassword ( string domainname, string username, string oldpassword, string newpassword ) : string
UserDel ( string username ) : Boolean

delete a local user based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD

UserExists ( string username ) : Boolean

return true if a local user exists

UserExists ( string username, string domain ) : Boolean

return true if a local user exists

UserGet ( string username, string domain, structenums &userinfo4 ) : Boolean

returns local user settings as a ref of an USER_INFO_4 struct based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD

UserGet ( string username, structenums &userinfo4 ) : Boolean

returns local user settings as a ref of an USER_INFO_4 struct based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD

UserMod ( string username, structenums userInfo4 ) : Boolean

modify local user settings based on a USER_INFO_4 struct based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD

ValidateCredentials ( string username, string password ) : bool

Attempts to validate the user's credentials for a local account using a pInvoke to LogonUser.

ValidateCredentials ( string username, string domain, string password ) : bool

Attempts to validate the user's credentials using a pInvoke to LogonUser.

ValidateUser ( string username, string domain, string password ) : bool

Attempts to validate the user's credentials using a pInvoke to LogonUser but ignores password change response.

VersionsInfo ( ) : structenums.OSVERSIONINFOW

get the real windows version http://www.codeproject.com/Articles/678606/Part-Overcoming-Windows-s-deprecation-of-GetVe

WTSQueryUserToken ( int sessionId ) : IntPtr
WTSRegister ( IntPtr handle ) : bool
WTSUnRegister ( IntPtr handle ) : bool

Private Methods

Method Description
GetDomainInfo ( string domain ) : pInvokes.SafeNativeMethods.DOMAIN_CONTROLLER_INFO
LogonUser ( string username, string domain, string password ) : int
RegistryLoadSetPrivilege ( ) : Boolean

Method Details

CloseHandle() public static method

public static CloseHandle ( IntPtr handle ) : bool
handle System.IntPtr
return bool

CreateUserProfileDir() public static method

calls API CreateProfile an empty string on error a null string on already exists a string on success
public static CreateUserProfileDir ( IntPtr hToken, string username ) : string
hToken System.IntPtr
username string
return string

DeleteProfile() public static method

public static DeleteProfile ( System.Security.Principal.SecurityIdentifier sid ) : bool
sid System.Security.Principal.SecurityIdentifier
return bool

DisconnectNetworkDrive() public static method

disconnecting an UNC share
public static DisconnectNetworkDrive ( string remoteUNC ) : System.Boolean
remoteUNC string
return System.Boolean

DomainMember() public static method

query if the domain is part of a domain tree in which the local computer is a member of
public static DomainMember ( string domain ) : bool
domain string
return bool

GetCredentials() public static method

public static GetCredentials ( string caption, string message ) : NetworkCredential
caption string
message string
return System.Net.NetworkCredential

GetFreeShareSpace() public static method

Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread. based on http://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
public static GetFreeShareSpace ( string share ) : long[]
share string
return long[]

GetInteractiveUserList() public static method

public static GetInteractiveUserList ( ) : List
return List

GetMachineDomainMembership() public static method

get local machine domain membership as NETBIOS name
public static GetMachineDomainMembership ( ) : string
return string

GetMachineDomainMembershipEX() public static method

get local machine domain membership as DNS name
public static GetMachineDomainMembershipEX ( ) : string
return string

GetOrSetUserProfileDir() public static method

get or create user profile directory only if the ProfileList regkey is not of SID.bak (Abstractions.User.FixProfileList) an empty or null string means error
public static GetOrSetUserProfileDir ( string username, string domain, string password ) : string
username string
domain string
password string
return string

GetRegistryLocation() public static method

get RegistryKey from structenums.RegistryLocation
public static GetRegistryLocation ( structenums location ) : RegistryKey
location structenums
return Microsoft.Win32.RegistryKey

GetSessionContext() public static method

returns a Dictionary of SessionID Keys and a List of usernames based on context in which a program is running. a program running as administrator will add administrator to the list
public static GetSessionContext ( ) : List>.Dictionary
return List>.Dictionary

GetSessionContext() public static method

return username based on context in which a program is running. a program running as administrator will add administrator to the list session ID -1 retuns all sessions instead of a specific one
public static GetSessionContext ( int sessionID ) : List
sessionID int the seesion ID or -1 for all sessions
return List

GetSessionContextParser() public static method

return username based on context in which a program is running. a program running as administrator will add administrator to the list session ID -1 retuns all sessions instead of a specific one
public static GetSessionContextParser ( int sessionID, Dictionary contextALL ) : List
sessionID int the seesion ID or -1 for all sessions
contextALL Dictionary a GetSessionContext() Directory
return List

GetSessionId() public static method

public static GetSessionId ( ) : int
return int

GetUserDomain() public static method

public static GetUserDomain ( int sessionId ) : string
sessionId int
return string

GetUserName() public static method

public static GetUserName ( int sessionId ) : string
sessionId int
return string

GetUserProfileDir() public static method

returns userprofile based on GetUserProfileDirectory only if the ProfileList regkey is not of SID.bak (Abstractions.User.FixProfileList) empty string means error
public static GetUserProfileDir ( IntPtr hToken ) : string
hToken IntPtr
return string

GetUserProfilePath() public static method

returns userprofile based on SHGetFolderPath only if the profile realy exists and the ProfileList regkey is not of SID.bak (Abstractions.User.FixProfileList) empty string means error
public static GetUserProfilePath ( IntPtr hToken ) : string
hToken IntPtr
return string

GetUserToken() public static method

Create a handle to the user token make sure to close the handle!!!
public static GetUserToken ( string username, string domain, string password ) : IntPtr
username string
domain string
password string
return IntPtr

IsSessionLoggedOFF() public static method

public static IsSessionLoggedOFF ( int session ) : bool
session int
return bool

LastError() public static method

returns GetLastWin32Error as string
public static LastError ( ) : string
return string

LastError() public static method

returns GetLastWin32Error as string
public static LastError ( int error ) : string
error int
return string

LogoffSession() public static method

public static LogoffSession ( int sessionId ) : bool
sessionId int
return bool

MapNetworkDrive() public static method

connect to a remote computer based on http://social.msdn.microsoft.com/Forums/et-EE/netfxbcl/thread/58159e0e-aa45-4d46-a128-596c3d23ff5c
public static MapNetworkDrive ( string remoteUNC, string username, string password ) : Boolean
remoteUNC string
username string better use the domainname\username format
password string
return Boolean

MapNetworkDrive() public static method

connect to a remote computer based on http://social.msdn.microsoft.com/Forums/et-EE/netfxbcl/thread/58159e0e-aa45-4d46-a128-596c3d23ff5c
public static MapNetworkDrive ( string remoteUNC, string username, string password, bool promptUser ) : Boolean
remoteUNC string
username string better use the domainname\username format
password string
promptUser bool true to for a promt, if needed
return Boolean

MapNetworkDrive() public static method

Map a network drive.
public static MapNetworkDrive ( string unc, string drive, string user, string password ) : int
unc string The full UNC path.
drive string The drive letter (e.g. "Z:", "X:", etc.)
user string The username, null if you want the current user.
password string The password, null to use the default password.
return int

RegistryCloseKey() public static method

public static RegistryCloseKey ( UIntPtr hKey ) : Boolean
hKey UIntPtr
return Boolean

RegistryCopyKey() public static method

public static RegistryCopyKey ( UIntPtr hKey_src, string SubKey, UIntPtr hKey_dst ) : Boolean
hKey_src UIntPtr
SubKey string
hKey_dst UIntPtr
return Boolean

RegistryCreateKey() public static method

public static RegistryCreateKey ( structenums RootKey, string SubKey ) : UIntPtr
RootKey structenums
SubKey string
return UIntPtr

RegistryDeleteTree() public static method

public static RegistryDeleteTree ( structenums RootKey, string SubKey ) : Boolean
RootKey structenums
SubKey string
return Boolean

RegistryLoad() public static method

load a regfile at hklm or hku
public static RegistryLoad ( structenums where, string name, string file ) : Boolean
where structenums hklm or hku
name string The name of the key to be created under hKey. This subkey is where the registration information from the file will be loaded
file string
return Boolean

RegistryOpenKey() public static method

public static RegistryOpenKey ( structenums RootKey, string SubKey ) : UIntPtr
RootKey structenums
SubKey string
return UIntPtr

RegistryUnLoad() public static method

unload regfile from regkey
public static RegistryUnLoad ( structenums where, string name ) : Boolean
where structenums hklm or hku
name string
return Boolean

SendMessageToUser() public static method

send a messagebox to a session
public static SendMessageToUser ( int sessionID, string title, string message ) : Boolean
sessionID int
title string
message string
return Boolean

SetPreshutdownTimeout() public static method

public static SetPreshutdownTimeout ( SafeHandle handle, structenums &myServiceStatus ) : bool
handle SafeHandle
myServiceStatus structenums
return bool

SetServiceStopped() public static method

public static SetServiceStopped ( IntPtr handle, structenums &myServiceStatus ) : bool
handle IntPtr
myServiceStatus structenums
return bool

ShutdownPending() public static method

public static ShutdownPending ( IntPtr handle, structenums &myServiceStatus, TimeSpan wait ) : bool
handle IntPtr
myServiceStatus structenums
wait TimeSpan
return bool

StartProcessInSession() public static method

public static StartProcessInSession ( int sessionId, string cmdLine ) : Process
sessionId int
cmdLine string
return System.Diagnostics.Process

StartProcessInSessionWait() public static method

public static StartProcessInSessionWait ( int sessionId, string cmdLine ) : bool
sessionId int
cmdLine string
return bool

StartProcessWithToken() public static method

public static StartProcessWithToken ( IntPtr token, string cmdLine ) : Process
token IntPtr
cmdLine string
return System.Diagnostics.Process

StartUserProcessInSession() public static method

public static StartUserProcessInSession ( int sessionId, string cmdLine ) : bool
sessionId int
cmdLine string
return bool

StartUserProcessInSessionWait() public static method

public static StartUserProcessInSessionWait ( int sessionId, string cmdLine ) : bool
sessionId int
cmdLine string
return bool

UserADD() public static method

add user to the local system based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD
public static UserADD ( string username, string password, string comment ) : Boolean
username string
password string
comment string
return Boolean

UserChangePassword() public static method

public static UserChangePassword ( string domainname, string username, string oldpassword, string newpassword ) : string
domainname string
username string
oldpassword string
newpassword string
return string

UserDel() public static method

delete a local user based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD
public static UserDel ( string username ) : Boolean
username string
return Boolean

UserExists() public static method

return true if a local user exists
public static UserExists ( string username ) : Boolean
username string
return Boolean

UserExists() public static method

return true if a local user exists
public static UserExists ( string username, string domain ) : Boolean
username string
domain string
return Boolean

UserGet() public static method

returns local user settings as a ref of an USER_INFO_4 struct based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD
public static UserGet ( string username, string domain, structenums &userinfo4 ) : Boolean
username string
domain string
userinfo4 structenums a ref of an USER_INFO_4 struct
return Boolean

UserGet() public static method

returns local user settings as a ref of an USER_INFO_4 struct based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD
public static UserGet ( string username, structenums &userinfo4 ) : Boolean
username string
userinfo4 structenums a ref of an USER_INFO_4 struct
return Boolean

UserMod() public static method

modify local user settings based on a USER_INFO_4 struct based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD
public static UserMod ( string username, structenums userInfo4 ) : Boolean
username string
userInfo4 structenums
return Boolean

ValidateCredentials() public static method

Attempts to validate the user's credentials for a local account using a pInvoke to LogonUser.
public static ValidateCredentials ( string username, string password ) : bool
username string The username
password string The password
return bool

ValidateCredentials() public static method

Attempts to validate the user's credentials using a pInvoke to LogonUser.
public static ValidateCredentials ( string username, string domain, string password ) : bool
username string The username
domain string The domain
password string The password
return bool

ValidateUser() public static method

Attempts to validate the user's credentials using a pInvoke to LogonUser but ignores password change response.
public static ValidateUser ( string username, string domain, string password ) : bool
username string The username
domain string The domain
password string The password
return bool

VersionsInfo() public static method

get the real windows version http://www.codeproject.com/Articles/678606/Part-Overcoming-Windows-s-deprecation-of-GetVe
public static VersionsInfo ( ) : structenums.OSVERSIONINFOW
return structenums.OSVERSIONINFOW

WTSQueryUserToken() public static method

public static WTSQueryUserToken ( int sessionId ) : IntPtr
sessionId int
return IntPtr

WTSRegister() public static method

public static WTSRegister ( IntPtr handle ) : bool
handle IntPtr
return bool

WTSUnRegister() public static method

public static WTSUnRegister ( IntPtr handle ) : bool
handle IntPtr
return bool