Thank you guys.

OK, here is the problem:
We have a database where users get locked from time to time.
I need to provide the users with a way to unlock themselves.

The proper way to unlock the users is to:
1. Run a CLI utility to get ProcessID of the user's server instance.
2. Kill the user's Process on the server.
3. Run a second CLI utility to unlock the user in the database
4. Delete any files created by the user.

I went with BrianTX's solution: Topic: remote execution. And it works fine.

Now I have another problem:
The CLI utilities has to be provided with Administrator's username and password.
How do I hide the username and password?
(Setting Permissions on the script to Execute only doesn't work!!) [Wink]

And here is what I have come up with:

code:
;-----Define Variables--------------------------------------------------

$UserName = @UserID
$RemoteBox = "SERVER1"
$ServerShr = "\\SERVER1\Unlock$"
$DbWorkShr = "\\SERVER1\Work"
$ServerFile = "\\SERVER1\Unlock$\PList.txt"

$DBAName = "administrator"
$DBApw = "password"


;-----Find ProcessID----------------------------------------------------

Shell "CMD /C " + $ServerShr + "\DbAdmin.exe " + $RemoteBox + " -u " + $DBAName + " -p " + $DBApw + " -r >" + $ServerFile

$Nul = Open(1,$ServerFile)
$UserPID = ReadLine(1)
While @ERROR = 0
$Read1 = ReadLine(1)
If InStr($Read1, $UserName)
$PID = LTrim(SubStr($Read1, 1, 3))
Else
EndIf
Loop
$Nul = Close(1)
DEL $ServerFile


;-----Kill ProcessID----------------------------------------------------

$NameSpace = "root\cimv2"
$RCommand = "C:\NTReskit\Kill.exe " + $PID

$SysLoc = CreateObject("WbemScripting.SWbemLocator")
$SysSet = $SysLoc.ConnectServer($RemoteBox, $NameSpace, $DBAName, $DBApw)
$SysSet.Security_.ImpersonationLevel = 3

$objProcStart = $SysSet.Get("Win32_ProcessStartup")
$ProcStartInst = $objProcStart.SpawnInstance_
$ProcStartInst.Put_

$objProc = $SysSet.Get("Win32_Process")
$objProcInst = $ObjProc.Methods_("Create").InParameters.SpawnInstance_
$objProcInst.CommandLine = $RCommand
$objProcInst.ProcessStartupInformation = $ProcStartInst
$objProcOut = $SysSet.ExecMethod("Win32_Process","Create",$objProcInst)


;-----Unlock DB User----------------------------------------------------

$RCommand = "D:\DBsearch\Bin\DBlock.exe -unlock -user " + $UserName

$SysLoc = CreateObject("WbemScripting.SWbemLocator")
$SysSet = $SysLoc.ConnectServer($RemoteBox, $NameSpace, $DBAName, $DBApw)
$SysSet.Security_.ImpersonationLevel = 3

$objProcStart = $SysSet.Get("Win32_ProcessStartup")
$ProcStartInst = $objProcStart.SpawnInstance_
$ProcStartInst.Put_

$objProc = $SysSet.Get("Win32_Process")
$objProcInst = $ObjProc.Methods_("Create").InParameters.SpawnInstance_
$objProcInst.CommandLine = $RCommand
$objProcInst.ProcessStartupInformation = $ProcStartInst
$objProcOut = $SysSet.ExecMethod("Win32_Process","Create",$objProcInst)


;-----Delete User Files-------------------------------------------------

$UserFile = $DbWorkShr + $UserName + ".upd"

If Exist($UserFile)
$Result1 = GetFileTime($UserFile)
$FileName = Dir($DbWorkShr)
While $FileName <> "" AND @ERROR = 0
$Result2 = GetFileTime($DbWorkShr + $FileName)
If $Result2 = $Result1
DEL $DbWorkShr + $FileName
Else
EndIf
$FileName = Dir()
Loop
Else
Endif



[ 26. October 2002, 18:05: Message edited by: KiXtart_HelpDesk ]