Solved

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

Posted on 2010-11-11
8
663 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

947 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

16 Experts available now in Live!

Get 1:1 Help Now