Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What path is used when Shell is called 2

Status
Not open for further replies.

djburnheim

Technical User
Jan 22, 2003
71
0
0
AU
I've been working on a small app that calls a command line exe file (see thread222-681160) and I almost have it working now but am running into two problems. Firstly the command line exe file needs to be run from the same location as a DAT file and I've tried copying this DAT file to all the locations I can think of (windows, system32, system, root) but it doesn't seem to work so I'm not sure what path is used when Shell is called? The other problem I have is with the txt output file, from what I understand OPEN should create a file if it doesn't exsist but it doesn't so I have to leave it when I'd prefer to delete it. Running the below command from a DOS prompt works everytime with no problems (assuming the DAT file exsists in the path I'm in) and creates or overwrites the txt file as is it should but I just can't get it working from VB...any suggestions???

C:\SomeDOSPath\>d:\pgen\generator txtmachinename > d:\pgen\pw.txt

[red]***code***[/red]
[blue]
Private Sub cmdGenerate_Click()

Dim strTemp As String
Dim intFile As Integer

If frmMain.txtMachineName = "" Then
MsgBox "Please Enter Machine Name First!", vbExclamation, "No Machine Name"
frmMain.txtMachineName.SetFocus
GoTo NoMachineName:
End If

strTemp = "D:\PGen\Generator" & Chr(32) & frmMain.txtMachineName & ">D:\PGen\pw.txt"
Call Shell(strTemp, 0)
intFile = FreeFile()
Open "D:\PGen\pw.txt" For Input As #intFile
Line Input #intFile, strTemp
Close #intFile
[green] 'Kill "D:\PGen\pw.txt"[/green]

frmMain.cmdAnother.Visible = True
frmMain.cmdAnother.Enabled = True
frmMain.cmdGenerate.Visible = False
frmMain.cmdGenerate.Enabled = False
frmMain.lblAdmin.Visible = True
frmMain.lblPassword.Caption = strTemp
frmMain.lblPassword.Visible = True
frmMain.lblRemember.Visible = True
frmMain.lblExample.Visible = True
frmMain.cmdClose.SetFocus

NoMachineName:
End Sub[/blue]
 
> OPEN should create a file if it doesn't exist

Only when opening for Output/Append.

Try putting the DAT file in App.Path folder then before you call shell do a ChDir App.Path OR put the DAT file in D:\PGen. I would guess the DAT file needs to be in either App.Path folder or D:\PGen. Can you supply a path to the DAT file as a command-line argument?

Hope this helps.

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Of course, you can always use the "CD" command to tell you where Shell starts:
Code:
Dim lngX As Long
lngX = Shell("CMD.EXE /C CD > C:\MyDir.txt")
"CMD.EXE" is for NT/XP/2K - use "COMMAND.COM" for Win9x


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Andy thanks for your suggestions. I've already tried having the DAT file in D:\PGen and I tried your suggestion of having in the App.Path folder and changing directory before calling Shell but same result (I added those couple of lines to check the path and I've got it in the directory given in MyDir.txt)...I don't get any errors but nothing is being generated in the text file where as if I do it from a command line it does. There doesn't seem to be away to supply the path to DAT file at the command prompt and I might actually be going up the garden path with the location thing..but I did find when I was testing the command line string in DOS that I needed it in the path I was in to get any output in the txt file - the problem may be something else but I have no ideas!!

Thanks
Dave
[hammer]
 
How about swapping to the folder that originally contained the DAT file. Are there any ini/config files or registry entries pertaining to the PGen\Generator application?

Of course, it may just be one of those incredibly unco-operative applications...

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Tried changing to original location too but no go. The generator "app" was emailed to me...I don't know where it came from originally and all it is, is the exe file & dat file.

Dave
 
I don't suppose that if you load the generator app into DEBUG.EXE you can find a company name can you? It might even help you work out where it expects to find the curséd DAT file.

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Dave, after reading through your messages, it sounds like the .exe file you are running is not running properly and therefore is not creating the .txt file.

I have a couple of questions

1. What is in frmMain.txtMachineName immediately before you execute the shell command?

2. if you capture the value in strTemp (through immediate window or a watch) and type it in DOS EXACTLY as it appears does it work? I only ask this because the shell command may be getting confused.

Don
 
Hi Don, txtMachineName is alphanumeric entry.

eg
txtMachineName = ab12345
strTemp = D:\PGen\Generator ab12345>D:\Pgen\pw.txt

If I go into DOS and change directories to the app path (I've added this line after Andy's suggestions) and copy the value of strTemp it works.
 
How long does it take for the command (generator) to complete? If the shell command is still running then the .txt file won't be created until the command completes and thus would not be visible to the next line of code.
 
It runs and finishes almost straight away...If I check the txt file after the code has finished it isn't changed either.

I've been trying to work our how to "load the generator app into DEBUG.EXE" but have never used it before and can't work it out.

Dave
 
Dave

Assuming Win98 here...

Start \ Programs \ MS-Dos Prompt

DEBUG D:\PGen\Generator.exe

Then use d <return> to &quot;dump&quot; the code onto the screen.

You may or may not see something useful.

q <return> quits DEBUG

EXIT returns to Windows.

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;Why does my program keep showing error messages every time something goes wrong?&quot;
 
I'm working on XP and have tried that syntax for DEBUG.EXE but get &quot;file not found&quot;. I think .Net Studio can open exe files but I only have VB 6.
 
Ok, I think we've posted enough answers without actually answering his question. The question was, &quot;What path is used when Shell is called?&quot;

The path that is used is by default is the directory of your VB6 installation. Mine, by default, is:

C:\Program Files\Microsoft Visual Studio\VB98

It should be similar for yours if you just installed from the CD and didn't change the path. If you want to see what the actual path is, create a form with a button. Put this into the button code:

Shell(&quot;CMD.EXE CD&quot;)

It will call the command prompt, and use the CD command to return the path that is currently being used (typically when calling a command prompt, it's going to be the app's path, so if you have this in a different directory, it will logically be there).

Hope that answers your question.
 
Thanks I guess we hadn't actually posted the answer but Andy's code in the 3rd posting provided the path. I was hoping once I found what directory path was used when calling Shell I could fix my problem by putting the DAT file there but it doesn't so I'm really struggling to workout why I can put a string in at the command prompt and it works but if I pass that same string through VB it doesn't??...If anybody wants the generator.exe & dat file I'm more then happy to email them.

Dave
[hammer][cry]
 
As long as your generator.exe and the dat file are in the same directory, it should work just fine. Just call the generator.exe, have generator.exe's code call the dat file.

If you are looking for a command line option of changing the dat file (i.e. &quot;generator.exe mydat.dat&quot; or &quot;generator.exe yourdat.dat&quot;) and produce different outcomes based on the file sent as an argument to the program, you'll need to code your program a little differently.
 
AkutaSame, my problem is that I didn't write the generator.exe, I have no idea where it came from but it's been used to generate passwords based on machine names and I'm just trying to make it so you don't have to go into DOS each time you want to get a password.

Dave
 
Have you tried to see if the generator.exe gives any help?

thy (from a DOS prompt) generator /? or generator /h
 
Dave,

Do you want to try emailing the exe and dat to me and I'll see what I can see?

andy.watt @ lineone.net

Surely this has got to be a Noddy issue. (&quot;And don't call me Shirley&quot;)


Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;Why does my program keep showing error messages every time something goes wrong?&quot;
 
Dave, I've got some time this afternoon too, email it to me as well

don.peters @ earthlink.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top