printing - C# ShellExecute on windows 2012r2 incorrect work -


i have irritating problem , can't solve 30+ hours. please me because there friday evening , i'd go home.

what's problem?

my service tries invoke action file via shellexecutea function action doesn't invoked. when invoke action right click menu - action done correctly.

details create action txt , tif extensions:

  • txt: action name: a4, comand line: "c:\program files\windows\nt\accessories\wordpad.exe" /pt "%1" "printer" “%3”
  • tif: action name: a4, comand line: "c:\windows\system32\rundll32.exe" "c:\windows\system32\shimgvw.dll",imageview_printto /pt "%1" "printer" "%3" "%4"

where printer - name of printer. so, can see these commands configured printing file. in service wrote on c# use next code:

string size = "a4";//name of action file int returncode = shell32.shellexecuteany(0, ref size, ref sourcefilepath, 0, 0, 6); 

where shell32.shellexecuteany next:

[system.security.suppressunmanagedcodesecurity]     public static class shell32     {         [dllimport("shell32.dll", entrypoint = "shellexecutea", charset = charset.ansi, setlasterror = true, exactspelling = true)]         extern private static int shellexecutea(int hwnd, [marshalas(unmanagedtype.vbbyrefstr)] ref string lpoperation, [marshalas(unmanagedtype.vbbyrefstr)] ref string lpfile, intptr lpparameters, intptr lpdirectory, int nshowcmd);          public static int shellexecuteany(int hwnd, ref string lpoperation, ref string lpfile, int lpparameters, int lpdirectory, int nshowcmd)         {             int result;             gchandle handle = gchandle.alloc(lpparameters, gchandletype.pinned);             gchandle handle2 = gchandle.alloc(lpdirectory, gchandletype.pinned);             try             {                 intptr tmpptr = handle.addrofpinnedobject();                 intptr tmpptr2 = handle2.addrofpinnedobject();                  result = shellexecutea(hwnd, ref lpoperation, ref lpfile, tmpptr, tmpptr2, nshowcmd);             }                         {                 handle.free();                 handle2.free();             }             return result;         }     } 

so, when sourcefilepath txt file, it's tif file. , commands work correctly on windows7 , print files.

but when try on windows2012r2 noticed following things. firstly, txt files printed correctly. secondly, tif files aren't printed shellexecuteany returns 42(that means have worked correctly). when right click on tif file , press a4 file printed!!!

that's confused me. don't know can catch error or understand wrong. thanks.

update

as hans says use code:

var startinfo =new processstartinfo(sourcefilepath) {verb = "a4" };         if(startinfo.verbs.firstordefault(x=>x == "a4") == null)         {             logger.warn("some warning");             return false;         }         var newprocess = new process {startinfo = startinfo};          try         {             newprocess.start();         }         catch (exception ex)         {             logger.warn("some message");         } 

but problem same. on windows7 works fine. on windows 2012 no exceptions tif files verb doesn't work , pcl files isn't created. interesting problem?


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -