Can't successfully run batch file

Just starting out? Need help? Post your questions and find answers here.
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Can't successfully run batch file

Post 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?
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Can't successfully run batch file

Post by NicTheQuick »

Are you trying to run a 64 bit program from a 32 bit Purebasic program?
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: Can't successfully run batch file

Post by Jac de Lad »

I think so. I mean, I'm executing a batch file, shouldn't this be possible?
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: Can't successfully run batch file

Post 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.
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: Can't successfully run batch file

Post 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.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Can't successfully run batch file

Post 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.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: Can't successfully run batch file

Post 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.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Can't successfully run batch file

Post 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
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Can't successfully run batch file

Post 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
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: Can't successfully run batch file

Post 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!
Post Reply