AppData path - Execution not allowed?

Everything else that doesn't fall into one of the other PB categories.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

AppData path - Execution not allowed?

Post by c4s »

A new version of my program decompresses an executable to the AppData path and runs it when needed. Previously I used the TempPath but thought AppData would be better because it doesn't get cleared.
Now I received much feedback where my users said that the program doesn't work anymore. Well, I thought the error is somewhere else because I also switched to unicode (basically using this code) but yesterday I had the flash of genius that it must be because of accessing privileges of the AppData path?!

I wasn't able to find more information about that - msdn can be pretty overwhelming in information - so can you tell me if I'm right?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Fred
Administrator
Administrator
Posts: 18553
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: AppData path - Execution not allowed?

Post by Fred »

If you use the AppData for the logged user (ie: not the global appdata), then you shouldn't have any problem, you can safely write to it.
Thorium
Addict
Addict
Posts: 1314
Joined: Sat Aug 15, 2009 6:59 pm

Re: AppData path - Execution not allowed?

Post by Thorium »

Fred wrote:If you use the AppData for the logged user (ie: not the global appdata), then you shouldn't have any problem, you can safely write to it.
Yes, but the question is if you can execute there. Maybe some virusscanner block execution from that path.
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: AppData path - Execution not allowed?

Post by freak »

I'd think it is a security feature. Either by Windows itself, or its just a policy on your users computers.

It kind of makes sense too: The folder is meant for application settings only. Many users don't even know the folder exists, so it would be a good place to hide a malicious executable.
quidquid Latine dictum sit altum videtur
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: AppData path - Execution not allowed?

Post by c4s »

I send out some debug versions and the results are the same for TempPath and AppdataPath - it doesn't work. Now I found out that it must be CreateProcess_() from the following code that raises the error.
Freak and/or Fred could you please tell me what's different to the internal RunProgram() because I'm trying to emulate its behavior and just do it because ReadErrorString() doesn't work when used with an ascii executable out of my Unicode program.
Why doesn't CreateProcess_() work here ("program" is of course a valid executable that exists!):

Code: Select all

Structure PROCESS_OBJ
	hReadStdOut.i
	hWriteStdOut.i
	hReadStdErr.i
	hWwriteStdErr.i
	process.PROCESS_INFORMATION
	dataRead.i
	lastErrChar.ASCII
	lastStdChar.ASCII
EndStructure

Procedure proc_RunProgram(program.s, command.s, flags.l=0, *err.INTEGER=#Null)
	Define *this.PROCESS_OBJ, start.STARTUPINFO, sa.SECURITY_ATTRIBUTES, error

	*this = AllocateMemory(SizeOf(PROCESS_OBJ))
	error = 0

	;Create the Pipes
	sa\nLength =SizeOf(SECURITY_ATTRIBUTES)
	sa\bInheritHandle = 1
	sa\lpSecurityDescriptor = 0

	If CreatePipe_(@*this\hReadStdOut, @*this\hWriteStdOut, @sa, 0)
		If CreatePipe_(@*this\hReadStdErr, @*this\hWwriteStdErr, @sa, 0)
			start\cb = SizeOf(STARTUPINFO)
			start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES
			start\hStdOutput = *this\hWriteStdOut
			If flags & 2 = 2  ; #PROCESS_JOIN_OUTPUT
				start\hStdError = *this\hWriteStdOut
			Else
				start\hStdError = *this\hWwriteStdErr
			EndIf

			If CreateProcess_(#Null, program + " " + command, @sa, @sa, #True, #NORMAL_PRIORITY_CLASS, #Null, #Null, @start, @*this\process)
				CloseHandle_(*this\hWriteStdOut)
				CloseHandle_(*this\hWwriteStdErr)
			Else ;CreateProcess error
				error = -3
			EndIf
		Else ;pipe error
			error = -2
		EndIf
	Else ;pipe error
		error = -1
	EndIf

	If *err : *err\i = error : EndIf

	If error=0
		ProcedureReturn *this
	Else ;error
		CloseHandle_(*this\hReadStdErr)
		CloseHandle_(*this\hReadStdOut)
		CloseHandle_(*this\hWriteStdOut)
		CloseHandle_(*this\hWwriteStdErr)
		FreeMemory(*this)
		ProcedureReturn #False
	EndIf
EndProcedure
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: AppData path - Execution not allowed?

Post by Mistrel »

I can't find a reference. I know we can read/write/delete from our local app data folder as well as "all users". But I never considered whether we could execute something from there. :?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: AppData path - Execution not allowed?

Post by c4s »

I'm pretty ashamed but it looks like the solution is to modify that line:

Code: Select all

If CreateProcess_(#Null, program + " " + command, @sa, @sa, #True, #NORMAL_PRIORITY_CLASS, #Null, #Null, @start, @*this\process)
...to this:

Code: Select all

If CreateProcess_(#Null, #DQUOTE$ + program + #DQUOTE$ + " " + command, @sa, @sa, #True, #NORMAL_PRIORITY_CLASS, #Null, #Null, @start, @*this\process)
I send this fix out and it seems to work on their pc's.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Post Reply