?
Solved

VBS script help needed

Posted on 2013-11-13
7
Medium Priority
?
726 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
[X]
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
7 Comments
 
LVL 52

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 56

Expert Comment

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

~bp
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 56

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 85

Accepted Solution

by:
oBdA earned 1500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

752 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