?
Solved

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

Posted on 2010-11-11
8
Medium Priority
?
680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 1600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

777 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