J
Jeremy Chapman
The following is the original c++ header from wtsapi32.h followed by my
DLLImport syntax so that I can call the function from a c# application. Is
my DLL Import syntax correct? Every call to the function seems to return
false, with nothing in strBuffer or lBytesReturned.
/*BOOL WINAPI WTSQueryUserConfigA(
IN LPSTR pServerName,
IN LPSTR pUserName,
IN WTS_CONFIG_CLASS WTSConfigClass,
OUT LPSTR * ppBuffer,
OUT DWORD * pBytesReturned);*/
public enum enWTSClass
{
//Initial program settings
WTSUserConfigInitialProgram = 0x0, // string returned/expected
WTSUserConfigWorkingDirectory = 0x1, // string
returned/expected
WTSUserConfigfInheritInitialProgram = 0x2, // DWORD
returned/expected
//
WTSUserConfigfAllowLogonTerminalServer = 0x3, //DWORD returned/expected
//Timeout settings
WTSUserConfigTimeoutSettingsConnections = 0x4, //DWORD returned/expected
WTSUserConfigTimeoutSettingsDisconnections = 0x5, //DWORD returned/expected
WTSUserConfigTimeoutSettingsIdle = 0x6, //DWORD returned/expected
//Client device settings
WTSUserConfigfDeviceClientDrives = 0x7, //DWORD returned/expected
WTSUserConfigfDeviceClientPrinters = 0x8, //DWORD returned/expected
WTSUserConfigfDeviceClientDefaultPrinter = 0x9, //DWORD returned/expected
//Connection settings
WTSUserConfigBrokenTimeoutSettings = 0xA, //DWORD returned/expected
WTSUserConfigReconnectSettings = 0xB, //DWORD returned/expected
//Modem settings
WTSUserConfigModemCallbackSettings = 0xC, //DWORD returned/expected
WTSUserConfigModemCallbackPhoneNumber = 0xD, // string
returned/expected
//Shadow settings
WTSUserConfigShadowingSettings = 0xE, //DWORD returned/expected
//User Profile settings
WTSUserConfigTerminalServerProfilePath = 0xF, // string
returned/expected
//Terminal Server home directory
WTSUserConfigTerminalServerHomeDir = 0x10, // string
returned/expected
WTSUserConfigTerminalServerHomeDirDrive = 0x11, // string
returned/expected
WTSUserConfigfTerminalServerRemoteHomeDir = 0x12 // DWORD 0:LOCAL 1:REMOTE
};
[DllImport("wtsapi32.dll")]
private static extern bool WTSQueryUserConfigA(
string strServerName,
string strUserName,
enWTSClass eWTSConfigClass,
ref string strBuffer,
ref long lBytesReturned);
DLLImport syntax so that I can call the function from a c# application. Is
my DLL Import syntax correct? Every call to the function seems to return
false, with nothing in strBuffer or lBytesReturned.
/*BOOL WINAPI WTSQueryUserConfigA(
IN LPSTR pServerName,
IN LPSTR pUserName,
IN WTS_CONFIG_CLASS WTSConfigClass,
OUT LPSTR * ppBuffer,
OUT DWORD * pBytesReturned);*/
public enum enWTSClass
{
//Initial program settings
WTSUserConfigInitialProgram = 0x0, // string returned/expected
WTSUserConfigWorkingDirectory = 0x1, // string
returned/expected
WTSUserConfigfInheritInitialProgram = 0x2, // DWORD
returned/expected
//
WTSUserConfigfAllowLogonTerminalServer = 0x3, //DWORD returned/expected
//Timeout settings
WTSUserConfigTimeoutSettingsConnections = 0x4, //DWORD returned/expected
WTSUserConfigTimeoutSettingsDisconnections = 0x5, //DWORD returned/expected
WTSUserConfigTimeoutSettingsIdle = 0x6, //DWORD returned/expected
//Client device settings
WTSUserConfigfDeviceClientDrives = 0x7, //DWORD returned/expected
WTSUserConfigfDeviceClientPrinters = 0x8, //DWORD returned/expected
WTSUserConfigfDeviceClientDefaultPrinter = 0x9, //DWORD returned/expected
//Connection settings
WTSUserConfigBrokenTimeoutSettings = 0xA, //DWORD returned/expected
WTSUserConfigReconnectSettings = 0xB, //DWORD returned/expected
//Modem settings
WTSUserConfigModemCallbackSettings = 0xC, //DWORD returned/expected
WTSUserConfigModemCallbackPhoneNumber = 0xD, // string
returned/expected
//Shadow settings
WTSUserConfigShadowingSettings = 0xE, //DWORD returned/expected
//User Profile settings
WTSUserConfigTerminalServerProfilePath = 0xF, // string
returned/expected
//Terminal Server home directory
WTSUserConfigTerminalServerHomeDir = 0x10, // string
returned/expected
WTSUserConfigTerminalServerHomeDirDrive = 0x11, // string
returned/expected
WTSUserConfigfTerminalServerRemoteHomeDir = 0x12 // DWORD 0:LOCAL 1:REMOTE
};
[DllImport("wtsapi32.dll")]
private static extern bool WTSQueryUserConfigA(
string strServerName,
string strUserName,
enWTSClass eWTSConfigClass,
ref string strBuffer,
ref long lBytesReturned);