Start and stop a window server of a distant server

Start and stop a window server of a distant server

Post by Nicholas P » Sun, 27 Jun 2004 01:49:47


Samuel,

You probably want to switch the context under which the call is being
made. You can make a call to the LogonUser API through the P/Invoke layer,
and then pass the handle to the Impersonate method on the
WindowsImpersonationContext class. Check out the documentation for the
Impersonate method on the WindowsImpersonationContext class for an example
on how to do this.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- XXXX@XXXXX.COM



us is the start and stop of Window service of distant server.
do the tasks.
System.ServiceProcess.ServiceController. But how can I give the
authentification parameters to access the server allowing to start or stop
the service ?
 
 
 

Start and stop a window server of a distant server

Post by U2FtdWV » Tue, 29 Jun 2004 17:58:01

Hi Nicholas,

I already tried to solve my problem the LogonUser of the API using this link http://www.yqcomputer.com/

It runs well giving my username and pwd of my local computer. I tried the same thing with the account of a colleague. In both cases I runs!
But when I tried it of our test server with an admin account, it doesn't work.

I become an error 1326 !?!? I connect myself in remote using the domain, username and pwd parameters I gave the Logon method without problem.

It should be something with rights, shouldn't it ?

I appreciate any suggestion to solve this problem.

tia
Samuel


private void DoWorkImpersonating(string p_username,string p_pwd, string p_domain)
{
int l_token1;
int ret=0 ;

bool loggedOn = LogonUser(
p_username,
p_domain ,
p_pwd,
// Logon type = LOGON32_LOGON_NETWORK_CLEARTEXT.
3,
// Logon provider = LOGON32_PROVIDER_DEFAULT.
0,
// The user token for the specified user is returned here.
out l_token1);

// Call GetLastError to try to determine why logon failed if it did not succeed.
if (loggedOn == false)
{
ret = GetLastError();
this.ResultTb.Text = "LogonUser() failed with error code: " + ret + "\r\n";
}
if (ret != 0)
throw new Exception ("Invalid Username or Password");
IntPtr token2 = new IntPtr(l_token1);
WindowsIdentity l_Wid = new WindowsIdentity (token2);
WindowsImpersonationContext l_mWIC = l_Wid.Impersonate();
//do work here impersonating the caller Identity

//RevertToself
l_mWIC.Undo ();
}

 
 
 

Start and stop a window server of a distant server

Post by U2FtdWV » Tue, 29 Jun 2004 18:06:01


an important precision : the server is a Windows 2003 Server Web Edition.