Solved

VBS script help needed

Posted on 2013-11-13
7
692 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 50

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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

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 84

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

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

Suggested Solutions

Title # Comments Views Activity
VBScript Issues 8 40
Math Equation 23 105
Assigning VBA code to a specific worksheet 3 31
Update Yearly Workbook With Weekly Workbook On Daily Basis For Each Region 6 20
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

840 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