Solved

Script for Stoping process/copy file/start application in remote computer

Posted on 2010-11-11
8
666 Views
Last Modified: 2012-05-10
Hi, I am looking for a script using which i can do the following.  Basically we have mutiple LCD TVs across three different cities. Every city have a Desktop where the pptview will run  a pps file  in a looping mode.

This should be automated using powershell or VB.

1- Check pptview.exe process is running on remote computer(s), if it is running kill the process.
2- Copy a PPS file from shared drive (on file server) to a remote computer ( authenticate with another user ID and password to connect remote computer, all the remote PCs will have same user ID and password)
3- start the pptview on remote computer with the newly copied PPS file.

I already have a script. But lot of issues with that...May be your fresh script will help.
0
Comment
Question by:moorthy_kulumani
  • 4
  • 2
  • 2
8 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 400 total points
ID: 34112177
here's the methods you need:
On Error Resume Next

sub ExecuteProcess(strComputerName, appPathDir, appPathFile)
	Dim strWinMgt
	strWinMgt = "winmgmts://" & strComputerName & ""
	
	Set Process = GetObject(strWinMgt).Get("Win32_Process")

	RetVal = Process.Create (appPathFile,appPathDir,null,PID)

	if RetVal <> 0 then
		wscript.echo "Error: " & Err.Description & ":" & Err.Number
	end if

end sub

sub KillProcess(strComputerName, strProcessKill)
	Dim strWinMgt
	strWinMgt = "winmgmts://" & strComputerName

	Set Processes = GetObject(strWinMgt).ExecQuery("select * from Win32_Process where Name = " & strProcessKill )
	for each Process in Processes
		RetVal = Process.Terminate(0)
	next

	if RetVal <> 0 then
		wscript.echo "Error: " & Err.Description & ":" & Err.Number
	end if

end sub

sub CopyRemoteFile(strSourceFile, strDestDir, remoteServer, strUsername, strPassword)
	
	strCommand = "cmd /c cmdkey /add:" & remoteServer & " /user:" & strUsername & " /pass:" & strPassword
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run strCommand, 0, True

	Set objFSO = CreateObject("Scripting.FileSystemObject")

	If Right(strDestDir, 1) <> "\" Then
		  strDestDir = strDestDir & "\"
	End If
	If objFSO.FileExists(strSourceFile) Then
		  If objFSO.FolderExists(strDestDir) Then
				objFSO.CopyFile strSourceFile, strDestDir, True
		  Else
				wscript.echo "Please check that the destination folder exists of:" & VbCrLf & strDestDir
		  End If
	Else
		  wscript.echo "Please check that the source file exists of:" & VbCrLf & strSourceFile
	End If

	strCommand = "cmd /c cmdkey /delete:" & remoteServer
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run strCommand, 0, True
end sub

Open in new window

0
 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 34114027
Can I get the full script with string definition

The computer where I am running the command = CompA
The remote computer where i kill the process = CompB
The process i kill = pptview.exe
The Drive where i copy file from = S:\AdvTV
File name = Nov10.pps
The remote computer where copy the file to  = CompB
Destination folder on the remote computer = C:\AdvTVLocal
The application i start on remote computer = pptview.exe c:\AdvTVLocal\Nov10.pps
0
 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 34114049
Please killing process and starting the application happens at the remote computer...
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 34114053
Please note killing process and starting the application happens at the remote computer...
0
 
LVL 11

Assisted Solution

by:Tasmant
Tasmant earned 100 total points
ID: 34114176
Just used the functions provided by sedgwick to call them with the settings you want.

On Error Resume Next

'Call function with settings you provide
KillProcess CompB pptview.exe
strSrcFile = "S:\AdvTV\" & "Nov10.pps"
CopyRemoteFile strSrcFile, "C:\AdvTVLocal", CompB
strDestProg = "pptview.exe c:\AdvTVLocal\Nov10.pps" 
ExecuteProcess CompB, strDestProg
'End calls

sub ExecuteProcess(strComputerName, appPathDir, appPathFile)
	Dim strWinMgt
	strWinMgt = "winmgmts://" & strComputerName & ""
	
	Set Process = GetObject(strWinMgt).Get("Win32_Process")

	RetVal = Process.Create (appPathFile,appPathDir,null,PID)

	if RetVal <> 0 then
		wscript.echo "Error: " & Err.Description & ":" & Err.Number
	end if

end sub

sub KillProcess(strComputerName, strProcessKill)
	Dim strWinMgt
	strWinMgt = "winmgmts://" & strComputerName

	Set Processes = GetObject(strWinMgt).ExecQuery("select * from Win32_Process where Name = " & strProcessKill )
	for each Process in Processes
		RetVal = Process.Terminate(0)
	next

	if RetVal <> 0 then
		wscript.echo "Error: " & Err.Description & ":" & Err.Number
	end if

end sub

sub CopyRemoteFile(strSourceFile, strDestDir, remoteServer, strUsername, strPassword)
	
	strCommand = "cmd /c cmdkey /add:" & remoteServer & " /user:" & strUsername & " /pass:" & strPassword
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run strCommand, 0, True

	Set objFSO = CreateObject("Scripting.FileSystemObject")

	If Right(strDestDir, 1) <> "\" Then
		  strDestDir = strDestDir & "\"
	End If
	If objFSO.FileExists(strSourceFile) Then
		  If objFSO.FolderExists(strDestDir) Then
				objFSO.CopyFile strSourceFile, strDestDir, True
		  Else
				wscript.echo "Please check that the destination folder exists of:" & VbCrLf & strDestDir
		  End If
	Else
		  wscript.echo "Please check that the source file exists of:" & VbCrLf & strSourceFile
	End If

	strCommand = "cmd /c cmdkey /delete:" & remoteServer
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run strCommand, 0, True
end sub

Open in new window

0
 
LVL 11

Expert Comment

by:Tasmant
ID: 34114184
Correct line 4 with:
KillProcess CompB, pptview.exe
0
 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 34114287
I understand the calling function...But For killing the process and starting the application we need to login to the remote machine.....I dont see any authentication happen in both the function....

And also the password cannot embedded with the code...we have to prompt from every user...only the users who are remote computer in administrator group should be able do all

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 34130090
i've added the authentication code for executing/killing process
On Error Resume Next

Dim user,pass,remote_domain,machine
remote_domain = InputBox("Enter remote domain:")
machine = InputBox("Enter remote machine:")
user = InputBox("Enter your user name:")
pass = InputBox("Enter your password:") 

sub ExecuteProcess(appPathDir, appPathFile)
	Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
	Set objSWbemServices = objSWbemLocator.ConnectServer(machine, _
		"root\cimv2", _
		 user, _
		 pass, _
		 "MS_409", _
		 "ntlmdomain:" + remote_domain)
	Set colSwbemObjectSet = objSWbemServices.Get("Win32_Process")

	RetVal = colSwbemObjectSet.Create (appPathFile,appPathDir,null,PID)

	if RetVal <> 0 then
		wscript.echo "Error: " & Err.Description & ":" & Err.Number
	end if

end sub

sub KillProcess(strProcessKill)
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
	Set objSWbemServices = objSWbemLocator.ConnectServer(machine, _
		"root\cimv2", _
		 user, _
		 pass, _
		 "MS_409", _
		 "ntlmdomain:" + remote_domain)

	Set Processes = objSWbemServices.ExecQuery("select * from Win32_Process where Name = " & strProcessKill )
	for each Process in Processes
		RetVal = Process.Terminate(0)
	next

	if RetVal <> 0 then
		wscript.echo "Error: " & Err.Description & ":" & Err.Number
	end if

end sub

sub CopyRemoteFile(strSourceFile, strDestDir, remoteServer)
	
	strCommand = "cmd /c cmdkey /add:" & remoteServer & " /user:" & user & " /pass:" & pwd
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run strCommand, 0, True

	Set objFSO = CreateObject("Scripting.FileSystemObject")

	If Right(strDestDir, 1) <> "\" Then
		  strDestDir = strDestDir & "\"
	End If
	If objFSO.FileExists(strSourceFile) Then
		  If objFSO.FolderExists(strDestDir) Then
				objFSO.CopyFile strSourceFile, strDestDir, True
		  Else
				wscript.echo "Please check that the destination folder exists of:" & VbCrLf & strDestDir
		  End If
	Else
		  wscript.echo "Please check that the source file exists of:" & VbCrLf & strSourceFile
	End If

	strCommand = "cmd /c cmdkey /delete:" & remoteServer
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run strCommand, 0, True
end sub

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
powershell function location 6 39
powershell add-content , set-content 2 23
powershell md/mkdir/New-item   -Quiet 10 43
powershell and invoke-command 4 21
Utilizing an array to gracefully append to a list of EmailAddresses
This article will help you understand what HashTables are and how to use them in PowerShell.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question