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
Solved

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

Posted on 2010-11-11
8
669 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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