简体   繁体   中英

Why won't my program run from the Program Files directory but will from anywhere else?

My program run fine from anywhere else on my drive apart from the Program Files directory (windows XP), I am logged on as administrator so I have full permissions to the drive. It runs fine from the root of c: the windows directory basically anywhere else apart from Program Files. I have recreated this problem on 4 different machines 2 XP, 2 Vista.

My program is a C# .Net 2.0 program. What on earth could the problem be?

I have even copied my entire project to the Program Files directory and I can't debug it from there it just won't run up, no errors at all.

Thanks for any help.

Just guessing, but if your program tries to save data to the program-directory, Vista will prevent this and change the path dynamically to something like c:\\users[user]\\AppData. Maybe this gives you a hint on whats going on.

Otherwise we need more info on your program to help you.

If you can't debug, you can always create a debug log. It is a bit slow, but in the end you will find the place where the program stops working.

LogDebug('before 1');
Statement1;
LogDebug('before 2');
Statement2;
LogDebug('before 3');
Statement3;
LogDebug('after 3');

I've tried the program on a fresh XP install that doesn't have any orgranizational policies applied.

:-(

The program does run from other folders with a space in the path such as Documents and Settings, the program does create a temporary file in the user profile\\appdata folder.

If I run the app several time from somewhere it will run from I've just noticed I get an error with the option to debug but VS won't show me the location of the problem I just get the error belo.

Unhandled exception at 0x79fb96a2 in test.exe: 0xC0000005: Access violation reading location 0x0000000c.

The problem can be recreated on XP and Vista.

Many thanks

如果这是由您公司的“老大哥”管理的机器,则听起来只能从“程序文件”中运行“允许的”应用程序

What does your programm read in its directory?

Why are you creating a temp file in user/appdata? For temporary files, you should use the API to get the temporary folder for the current profile and ideally an temporary filename, works like this:

string tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());

To help you properly, we need to know what your program should do on init.

Have you got any thing like Anti-virus software running?

Which is it?

  • Is it not running (probably OS related)
  • OR is it falling over (probably permissions)
  • OR running and not producing expected output? (probably permissions)

Have you checked the Event Logs?

Try calling it from a batch file and see what happens.

uhmm anyone want to try his .exe on their machine??

Sorry about this but I found the problem, I had some crap code that was looking for arguments being passed including 'file' and the file in 'program files' was forcing the program into a command line mode that has no gui. Really sorry to have wasted your time on such a trivial problem, you live and learn!

Thanks to all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM