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.
精彩评论