Solved

VBS script help needed

Posted on 2013-11-13
7
682 Views
Last Modified: 2013-12-10
I have the following vbs code.

The first one imports a key and the second one terminates a process.

I need the first part of the script to finish in order for the second one to execute. Can someone help out with that?

----------------------------------

On error resume next

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /K CD C:\Program Files (x86)\GNU\GnuPG\ & kleopatra.exe -i --import-certificate z:\255BD8BE19698491D80EA01A525F26535092FC41.pgp"
Set oShell = Nothing


strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Kleopatra.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next
0
Comment
Question by:llarava
7 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39644942
Pls try
const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
set oShell = WScript.CreateObject("WScript.Shell")
command = "cmd /K CD C:\Program Files (x86)\GNU\GnuPG\ & kleopatra.exe -i --import-certificate z:\255BD8BE19698491D80EA01A525F26535092FC41.pgp"
oShell.Run command, DontShowWindow, WaitUntilFinished

Open in new window

Regards
0
 

Author Comment

by:llarava
ID: 39645041
Hi,

The code opens the app then does the import of the key but then the app does not get closed.
I need the app to get closed after the key is imported.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39645141
Change the CMD /K to CMD /C, that will have it close when finished.

~bp
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:llarava
ID: 39645185
Here is the new code with the CMD /C - The app does not get closed.

const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
set oShell = WScript.CreateObject("WScript.Shell")
command = "cmd /C CD C:\Program Files (x86)\GNU\GnuPG\ & kleopatra.exe -i --import-certificate z:\255BD8BE19698491D80EA01A525F26535092FC41.pgp"
oShell.Run command, DontShowWindow, WaitUntilFinished
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39645248
It may be then that the kleopatra.exe program isn't designed to exit after processing the command line parms.  Does it bring up the UI for that application when you run this test?

~bp
0
 

Author Comment

by:llarava
ID: 39645264
Yes the UI shows and and the command is executed, however the app does not exit.

This is why I wanted to execute this code:

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Kleopatra.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39645686
Then you need to start the kleopatra process without waiting for it to end, wait a bit, end then end the process again. Using cmd.exe should not be necessary.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run Chr(34) & "C:\Program Files (x86)\GNU\GnuPG\kleopatra.exe" & Chr(34) & " -i --import-certificate z:\255BD8BE19698491D80EA01A525F26535092FC41.pgp", 1, False
Set oShell = Nothing
Wscript.Sleep 5000

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Kleopatra.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 84
split53 challenge 7 95
Need to delete empty sub dirs but not include the directory itself 10 80
How can I save all open docs into a given folder 12 113
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

786 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