Szuromi
asked on
VB script to remove user logon as service right
Hi Everybody,
I need to write a VBscript that will take remove service account from “Log on as a service” policy on the local computer.
I found a VB script which give user logon as service right but I need a VB script to remove user account from “Logon as a service” on local computer.
Thanks.
Szuromi
I need to write a VBscript that will take remove service account from “Log on as a service” policy on the local computer.
I found a VB script which give user logon as service right but I need a VB script to remove user account from “Logon as a service” on local computer.
Thanks.
Szuromi
ASKER
Hi Wizard,
Here is the vb script from ...
http://social.technet.microsoft.com/Forums/scriptcenter/en-US/bef48a92-6b59-481f-aab7-990ae2d4f31a/vbscript-to-give-user-logon-as-service-right?forum=ITCG
-------------------------- ---------- ---------- --------
Username = <domain\username> 'modify with your username
Dim oShell
Set oShell = CreateObject ("WScript.Shell")
oShell.Run "secedit /export /cfg config.inf", 0, true
oShell.Run "secedit /import /cfg config.inf /db database.sdb", 0, true
FileName = "config.inf"
OrgStr = "SeServiceLogonRight ="
RepStr = "SeServiceLogonRight = " & Username & ","
Set inputFile = CreateObject("Scripting.Fi leSystemOb ject").Ope nTextFile( "config.in f", 1,1,-1)
strInputFile = inputFile.ReadAll
inputFile.Close
Set inputFile = Nothing
Set outputFile = CreateObject("Scripting.Fi leSystemOb ject").Ope nTextFile( "config.in f",2,1,-1)
outputFile.Write (Replace(strInputFile,OrgS tr,RepStr) )
outputFile.Close
Set outputFile = Nothing
oShell.Run "secedit /configure /db database.sdb /cfg config.inf",0,true
set oShell= Nothing
Set obj = CreateObject("Scripting.Fi leSystemOb ject")
obj.DeleteFile("config.inf ")
obj.DeleteFile("database.s db")
-----------------
I tried to change it as you recommended but it does not seem to work for me. Would you please let me know what am I missing?
Thanks.
Here is the vb script from ...
http://social.technet.microsoft.com/Forums/scriptcenter/en-US/bef48a92-6b59-481f-aab7-990ae2d4f31a/vbscript-to-give-user-logon-as-service-right?forum=ITCG
--------------------------
Username = <domain\username> 'modify with your username
Dim oShell
Set oShell = CreateObject ("WScript.Shell")
oShell.Run "secedit /export /cfg config.inf", 0, true
oShell.Run "secedit /import /cfg config.inf /db database.sdb", 0, true
FileName = "config.inf"
OrgStr = "SeServiceLogonRight ="
RepStr = "SeServiceLogonRight = " & Username & ","
Set inputFile = CreateObject("Scripting.Fi
strInputFile = inputFile.ReadAll
inputFile.Close
Set inputFile = Nothing
Set outputFile = CreateObject("Scripting.Fi
outputFile.Write (Replace(strInputFile,OrgS
outputFile.Close
Set outputFile = Nothing
oShell.Run "secedit /configure /db database.sdb /cfg config.inf",0,true
set oShell= Nothing
Set obj = CreateObject("Scripting.Fi
obj.DeleteFile("config.inf
obj.DeleteFile("database.s
-----------------
I tried to change it as you recommended but it does not seem to work for me. Would you please let me know what am I missing?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, if using newer Windows, you don't have the correct rights when double clicking the vbs. So, run cmd in administrator mode, then use:
"cscript script.vbs"
"cscript script.vbs"
ASKER
Thanks your help!
SeServiceLogonRight =
After it is found, find either ",domain\user" and replace it with nothing or
after it is found, find either "domain\user," and replace it with nothing or
after it is found, find either "pcname\user," and replace it with nothing or
after it is found, find either ",pcname\user" and replace it with nothing or
after it is found, find either "user," and replace it with nothing or
after it is found, find either ",user" and replace it with nothing or (yes, let's try to be complete :) ), because you don't want the rest to be replaced, as mine says:
SeServiceLogonRight = *S-1-5-20,ASPNET
which would mess up a couple of things if I just empy the whole string to
SeServiceLogonRight =
(meaning no one will have the right)