Connecting Tech Pros Worldwide Help | Site Map

Set administrator privileges to WMI script

Newbie
 
Join Date: Aug 2007
Posts: 12
#1: Mar 13 '08
Hi,

I am trying to write a script that kills processes that generated by the OS on a localhost. The problem is that this script must be run under a user with administrator privileges, otheriwse the script wont be able to kill the processes.

Generally speaking, this script doesn't suppose to run under administrator but under a standard user privileges.

I am using the following commands in order to open the WMI connection:
Again, the WMI need to be executed locally and not remotely.

Expand|Select|Wrap|Line Numbers
  1. my $WMI = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate,(security)}//127.0.0.1" ) 
  2. $WMI->Security_->Privileges->AddAsString ('SeDebugPrivilege', 1);
Is there a way to set the script to connect to WMI using administrator privileges? (assuming, of course, that I have administrator credentials).

Thanks,

Ido.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,566
#2: Mar 14 '08

re: Set administrator privileges to WMI script


Quote:

Originally Posted by idoha

Hi,

I am trying to write a script that kills processes that generated by the OS on a localhost. The problem is that this script must be run under a user with administrator privileges, otheriwse the script wont be able to kill the processes.

Generally speaking, this script doesn't suppose to run under administrator but under a standard user privileges.

I am using the following commands in order to open the WMI connection:
Again, the WMI need to be executed locally and not remotely.

Expand|Select|Wrap|Line Numbers
  1. my $WMI = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate,(security)}//127.0.0.1" ) 
  2. $WMI->Security_->Privileges->AddAsString ('SeDebugPrivilege', 1);
Is there a way to set the script to connect to WMI using administrator privileges? (assuming, of course, that I have administrator credentials).

Thanks,

Ido.

To begin with, what is "WMI"? I haven't heard of that.

Doing things with Administrative privilage, especially remotely, is a definite NO NO. You will find that many places that set up machines for remote access, have it set to the administrator cannot log in remotely. This prevents questionable parties from doing so.

Regards,

Jeff
Newbie
 
Join Date: Mar 2008
Posts: 2
#3: Mar 14 '08

re: Set administrator privileges to WMI script


You need to use the swbemlocator like so:

Expand|Select|Wrap|Line Numbers
  1. $locator = Win32::OLE->CreateObject("WbemScripting.SWbemLocator");
  2. $WMI = $locator->ConnectServer( $computer, "root/cimv2", $user, $pass);
Newbie
 
Join Date: Aug 2007
Posts: 12
#4: Mar 14 '08

re: Set administrator privileges to WMI script


Hi,

I am familier with the "connect server" function you have suggested.
The only problem is that this is useful in order to run WMI on remote machines, while I need to run in on a local machine.
I tried to use the "connect server" to connect to localhost but it refused, saying that connection to localhosts are not permitted.

Any other options?

Thanks,

Ido.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,566
#5: Mar 14 '08

re: Set administrator privileges to WMI script


Quote:

Originally Posted by idoha

Hi,

I am familier with the "connect server" function you have suggested.
The only problem is that this is useful in order to run WMI on remote machines, while I need to run in on a local machine.
I tried to use the "connect server" to connect to localhost but it refused, saying that connection to localhosts are not permitted.

Any other options?

Thanks,

Ido.

If you are ON the machine that it will be running on, then why do you need to connect to it? Shouldn't you just have to run the command(s) you need?

Again, what is WMI?
Newbie
 
Join Date: Aug 2007
Posts: 12
#6: Mar 15 '08

re: Set administrator privileges to WMI script


Hi,

WMI stands for Windows Management Instrumentation. This is a set of extenstions by which you can retrieve information about the OS and manage its components like processes, services, memory, cpu usage etc..

My mail goal is to kill processes created by the OS. WMI is just one option to do that. Currently, all options including WMI are failing to terminate processes because administrator priviliges are required to kill those processes.

Since I intend to run the script on a local computer under a user which is not an administrator then I need to figure out a way to set the WMI command administrative privileges.

Thanks,
Ido.
Reply