Solved

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

Posted on 2010-11-11
8
659 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
 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 34114053
Please note killing process and starting the application happens at the remote computer...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now