开发者

Application can't write files when started through SHELL:STARTUP (Windows, C#)

开发者 https://www.devze.com 2023-02-16 02:10 出处:网络
I have an application in C# that runs perfectly when I start it manually. If I try to get it to run on computer start up by placing it in SHELL:STARTUP it fails at

I have an application in C# that runs perfectly when I start it manually.

If I try to get it to run on computer start up by placing it in SHELL:STARTUP it fails at

i.Save("screen" + index + ".bmp");

where index is an integer 0.

I catch the exception and the message is 'generic error in GD开发者_高级运维I+'.


The easiest way to fix it is to set "Start in" property of the shortcut to be folder where you want to store files.

Real fix as everyone else points out is to store files in location that you have access to as the user. Usual ways are:

  • specify it as argument to the program and pass to function that is saving the file
    • save to known locations (like My documents) - see Environmnet.Special folder to get correct path ( http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx)
  • save to temp folder by creating path with Path.GetTempFileName ( http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename.aspx)


This happens when the program does not have enough rights to write the image to disk. If you investigate the exception and inner exception details it should provide more information.

You need to try saving the image to a location which the application has write-access on.


Try specifying a complete path for screenX.bmp - in a directory where you have permission to create files.

0

精彩评论

暂无评论...
验证码 换一张
取 消