Jump to content

Remote Shutdown using the Windows API- Help with privileges

- - - - -

  • Please log in to reply
2 replies to this topic

#1
liamzebedee

liamzebedee

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
Currently I'm using this article as a guide to remotely shutting down a computer.

I'm using a setPriv function I wrote, which is supposed to set a privilege for the running program. However it keeps returning a 1300 erbool
setPriv(char privName){

	HANDLE hToken;

	TOKEN_PRIVILEGES tkp; 

	

	// Get a token for this process. 

 

	if (!OpenProcessToken(GetCurrentProcess(), 

		TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 

		return( FALSE ); 


	// Get the LUID for the shutdown privilege. 

	LPCWSTR privString = _T(""+privName);

	

	LookupPrivilegeValue(NULL, privString, 

		&tkp.Privileges[0].Luid); 


	tkp.PrivilegeCount = 1;  // one privilege to set    

	tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 

 

	// Get the shutdown privilege for this process. 

 

	AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 

        (PTOKEN_PRIVILEGES)NULL, 0); 

	return true;

}

and the code I'm using to shutdown computers, I'm guessing currently isn't working because it doesn't have the privileges.
setPriv((char)"SE_REMOTE_SHUTDOWN_NAME");

	setPriv((char)"SE_SHUTDOWN_NAME");


	LPTSTR lpMachineName = L""; // Name of the network machine to be shutdown

	LPTSTR lpMessage = L"You have been shutdown"; 

	DWORD dwTimeout = 60;

	BOOL bForceAppsClosed = false;  

	BOOL bRebootAfterShutdown = false;

	InitiateSystemShutdown(lpMachineName,

		lpMessage,

		dwTimeout,

		bForceAppsClosed,

		bRebootAfterShutdown);


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Shutting down a remote computer will depend on a LOT of things, including firewall settings, services running, etc, etc, etc.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
I would hope you practicing in an ideal environment. For example you can use virtual software and create a private network. That way you control everything. Then work you way up. As for the privileges, no experience there. Sorry :confused:
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users