Link to home
Create AccountLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

Shell

This code run perfectly file on VS2003, but when I put in on VS2008, it does not execute the c:\pgp\myEncryptPGP.bat file. Help.


Public Sub EnCrtFiles()


        Dim myDir, strfile
        Dim filename, savefilename, xPGPfilename, tmpfilename
        Dim cmdString

        myDir = "m:\server\pgp\cust\"
        cmdString = ""

        For Each strfile In System.IO.Directory.GetFiles(myDir, "*.mcr")
            filename = GetName(strfile)  ' GetName is a sub to get the name of a file

            xPGPfilename = myDir & Replace(filename, ".mcr", ".gpg")
            If File.Exists(xPGPfilename) = False Then
                cmdString = "c:\pgp\myEncryptPGP.bat " & strfile
                Shell(cmdString)

                txtFilesList.Text = "Encrypting myfile " & filename & vbCrLf & txtFilesList.Text
            End If
        Next
       
    End Sub
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Hi VBdotnet2005,

You can try Process.Start(cmdString, strfile)

But what it strfile ?
Avatar of VBdotnet2005

ASKER

strfile is the path and filename  to that file which needs to be encyrpted.


cmdString = "c:\pgp\myEncryptPGP.bat " & strfile  > "m:\server\pgp\cust\strfil.mcr"
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
error

Exception has been thrown by the target of an invocation.
And if you do that in DOS prompt it works ?
In VS2003, yes . It put a myfile.gpg  in  "m:\server\pgp\cust\" myfile.gpg

  For Each strfile In System.IO.Directory.GetFiles(myDir, "*.mcr")
            filename = GetName(strfile)  ' GetName is a sub to get the name of a file

            xPGPfilename = myDir & Replace(filename, ".mcr", ".gpg")
            If File.Exists(xPGPfilename) = False Then
                cmdString = "c:\pgp\myEncryptPGP.bat " & strfile
                Shell(cmdString)

                txtFilesList.Text = "Encrypting myfile " & filename & vbCrLf & txtFilesList.Text
            End If
        Next
And using only ?
Process.Start(cmdString)
If it works in VS2003 it should also work in VS2008, even with the Shell() command. Have you checked if anything is different ?
I checked c:\pgp\myEncryptPGP.bat that is where it is supposed to be.
And what's the result of ?
filename = GetName(strfile)
add a msgbox after this line
msgbox(filename)
filename  is the name of the file like  "A45678-080808142601.mcr"