Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shell String in VB.net

Posted on 2008-10-28
7
Medium Priority
?
773 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
  • 3
  • 2
5 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 1000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

782 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