Cannot access files on drive mapped network share from a Windows service

旧城冷巷雨未停 提交于 2019-11-28 12:13:44

Sorry; you can't access mapped drives from Windows services. As Sheng suggested, you can use a UI process to get the UNC path from a mapped drive and then pass this to the service, which must use the UNC path.

mapped drives are per session objects. So each interactive session has its own mapping and the service session has another drive mapping. In order to get the correct UNC path of a mapped drive you need to call WNetGetConnection in the correct session.

You can use any inter-session communication methods to initiate the request and get the result in the service, such as WCF, named pipe, sockets, etc.

hi elan i faced the same problem in my project and i found a solution

and is work expected follow my steps

                    if (api.Docusign_download(strDocuSignUserName, strDocuSignPassword, strDocuSignIntegratorKey, EnvelopeID, Environment.ExpandEnvironmentVariables("%temp%")) == true)
                    {
                        if (m_streamWriter1 != null)
                        {
                            m_streamWriter1.WriteLine(" This envelop id is  Downloaded and update the table" + EnvelopeID + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\n");
                        }

                        fpath1 = Environment.ExpandEnvironmentVariables("%temp%") + '\\' + EnvelopeID + '1' + ".pdf";
                        fpath2 = Environment.ExpandEnvironmentVariables("%temp%") + '\\' + EnvelopeID + '2' + ".pdf";
                        if (System.IO.File.Exists(fpath1))
                        {
                            fso = new FileSystemObject();
                            // fso.CopyFile(fileLoc, "\\\\Tech-Pro-01\\D\\", true); i download the file in temp folder and copy file to unc path ur expected work on reverse like access file to unc path he does not work directly but work in in direct access like temp folder to services
                            fso.CopyFile(fpath1, UNC, true);  
                            fso.CopyFile(fpath2, UNC, true);
                            fso.DeleteFile(fpath1, true);
                            fso.DeleteFile(fpath2, true);
                            //System.IO.File.Move(fileLoc, fileLocMove);

im just using legacy application script in vb fso file system object

1,make sure your map path access in iuser and network service access enable to the mapped provided machine 2,adding the reference system scripting

3, and unc path example \computername\sharedname\folder\filename 4,just fso.copyfile(uncpath,tempfoler,true) 5,u access a your file in temp folder he is access expected and work perfect

the temp folder access "c:\windows\temp because proceess can take the windows temp folder only

hope u elan he is work perfectly

thanks and regards

jagadeesh Govindaraj Pillai jagadeesh1492@facebook.com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!