Solved

Shell String in VB.net

Posted on 2008-10-28
7
764 Views
Last Modified: 2012-06-21
I have a VB.Net to perform encryption of files using PGP.

The line of argument,that is passed in the DOS Window is as below.
gpg  --recipient  "XXX"  --output "C:\Filename.zip.gpg"  --encrypt "C:\Filename.zip"

Here is my Function in VB.net.

            Dim GPG As New FileInfo("C:\Program Files\GNU\GnuPG\gpg.exe")
            Dim sGPGLocation As String
            Dim sCommandLine As String = Nothing
            Dim extension = ".gpg"
            'gpgEncryptName would be passed from a function eventually
            Dim gpgEncryptName As String = "C:\Testing.zip"
            Dim publicKey As String = "XXX"
            '-------Ensure we can find GPG.exe------
            If GPG.Exists = True Then
                sGPGLocation = "C:\Program Files\GNU\GnuPG\gpg.exe"
            Else
                Console.WriteLine("Error: Couldn't find GPG.EXE")
                'Return False
            End If
sCommandLine = """ & --recipient & """" """" "" & publicKey & "" """" """" & --output & """" """" "" & gpgEncryptName & extension & "" """" """" & --encrypt & """" """" "" & gpgEncryptName & """
Console.WriteLine(sCommandLine)
Shell("""--recipient & """ """ & publicKey & """ """ & --output & """ """ & gpgEncryptName """" & """" extension & """" --encrypt """" & """" gpgEncryptName """)
            'Return True
        Catch ex As IOException
            Console.WriteLine("Unable to locate GPG Software")

How can I represent gpg  --recipient  "XXX"  --output "C:\Filename.zip.gpg"
--encrypt "C:\Filename.zip"
in the Shell.Im not very familiar on how to represent empty space and [""] in the String.


0
Comment
Question by:analliah
[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
  • 3
  • 2
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22822020
I usually use the chr(34) equivalent...less confusing...have you tried something like this?

sCommandLine = " --recipient " & chr(34) &  publicKey & chr(34) & " --output " & chr(34) & gpgEncryptName & extension & chr(34) & " --encrypt " & chr(34) & gpgEncryptName & chr(34)
0
 
LVL 5

Author Comment

by:analliah
ID: 22822172
This is what I get
" --recipient "XXX" --output "C:\Testing.zip.gpg" --encrypt "C:\Testing.zip""

There is an extra " " at the very begining and end.
What does chr(34) represent ?
Is there a special character for space as well?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22822228
chr(34) is the equivalent of "If you don't need the others, simply remove them, but I think these are actually in the next line...no?sCommandLine = " --recipient " & chr(34) &  publicKey & chr(34) & " --output " & chr(34) & gpgEncryptName & extension & chr(34) & " --encrypt " & chr(34) & gpgEncryptName & chr(34)Console.WriteLine(sCommandLine)'Changing this next line work?Shell(sCommandLine)
0
 
LVL 5

Author Comment

by:analliah
ID: 22822234
My bad.It works fine.Thank You
What does chr(34) represent ?
Is there a special character for space as well?
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
ID: 22822246
site messed up my quotes in that last post, but yes chr(34) is the equivalent of a double quote (chr(39) is a single quote).
I usually just drop the space inside the quotes...glad it's working for you.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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