By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,847 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,847 IT Pros & Developers. It's quick & easy.

Set administrator privileges to WMI script

P: 12
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.
Mar 13 '08 #1
Share this Question
Share on Google+
5 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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
Mar 14 '08 #2

P: 2
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);
Mar 14 '08 #3

P: 12
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.
Mar 14 '08 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
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?
Mar 14 '08 #5

P: 12
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.
Mar 15 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.