Page 1 of 1

Can't successfully run batch file

Posted: Tue Jan 12, 2021 6:45 pm
by Jac de Lad
Hello,
I have a strange problem. I want to run a batch file from my program. If I run the batch file in the explorer it works find, but if I run it from program I get the "... is not recognized as internal or external command" error.
- the path variable is ok, I even added the full paths
- I can run the batch file in the windows explorer. I let succeeds always.
- I also tried calling it via ShellExec_(), that doesn't work.
- I tried calling the program directly, that doesn't work too.

The corresponding programs are qwinsta.exe and tscon.exe in the system folder. Do I need special rights to execute them?

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 7:03 pm
by NicTheQuick
Are you trying to run a 64 bit program from a 32 bit Purebasic program?

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 7:31 pm
by Jac de Lad
I think so. I mean, I'm executing a batch file, shouldn't this be possible?

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 7:51 pm
by Jac de Lad
I can't compile in x64 because:

Code: Select all

Import
GetConsoleWindow_() As "_GetConsoleWindow@0"
EndImport
produces an error and I don't know how to fix it because I copied it from a thread somewhere here.

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 7:55 pm
by Jac de Lad
Ok, so, cutting the code and trying again worked, it was indeed a 86/64 problem. Thanks, now I know how to go on. If anybody can help me with the snippet above everything would be alright.

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 8:03 pm
by NicTheQuick
Well, I have only guessed because I heard issues with that already. The permission model of Windows is split into x86 and x64 and running 64 bit programs from an 32 bit program usually does not work without workarounds.

Because I am not using Windows I can not help you with GetConsoleWindow_. I hope someone else can help you there. Maybe it also helps if you can write where you found than original code.

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 8:12 pm
by Jac de Lad
Yeah, strange. But I guess MS had something in mind.

I found it here:
viewtopic.php?f=12&t=59618

I guess it's some API import, but I'm not firm with that.

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 8:19 pm
by NicTheQuick
Well, it looks like the function will not be supported anymore and it is not recommended to use: https://docs.microsoft.com/en-us/window ... solewindow

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 8:20 pm
by Mijikai
Try this:

Code: Select all

Import "kernel32.lib"
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    GetConsoleWindow_() As "GetConsoleWindow"  
  CompilerElse
    GetConsoleWindow_() As "_GetConsoleWindow@0"
  CompilerEndIf
EndImport

Re: Can't successfully run batch file

Posted: Tue Jan 12, 2021 8:21 pm
by Jac de Lad
Yeah, just read that too. EnumWindows does the trick too.

@mijikai Thanks, that's working too. Now I have two options.
Thanks for your help!