Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 18,148 of 19,505    |
|    Matthew Wells to All    |
|    Get UNC from drive letter...    |
|    13 Mar 11 14:36:18    |
      From: matthew.wells@firstbyte.net              Hi everyone.              I have done quite a bit of research on this, but could not find a good       answer. I need to get the UNC path from a mapped drive letter where the       drive is mapped to another machine (not the SQL Server). The drive is       mapped the same on the server and all client stations. My main course was       to use sp_OACreate to create a filesystemobject and use the ShareName       property of the Drive object. The problem with that is that this only works       for the server's local C drive. When I try to use any mapped drive, it       fails. Here's what I've tried:              Declare       @src varchar(255), @desc varchar(255), @fso int, @Ret int, @DriveToken int,       @UNC nvarchar(100)              Exec @Ret = sp_OACreate 'Scripting.FileSystemObject', @fso out       Print @Ret       Exec @Ret = sp_OAMethod @fso, 'GetDrive', @DriveToken out, 'F'       Print @Ret       IF @Ret <> 0 Begin        Exec sp_OAGetErrorInfo @DriveToken, @src out, @desc out        Select hr=convert(varbinary(4),@Ret), Source=@src, Description=@desc       End              And the result of the error is:              0x800A0044 NULL NULL              Again, this works fine for C, but not for mapped drives.              I also found this:              Declare @Drive varchar(3), @Ret int       Set @Drive = 'C:\'              declare @objWNet int       declare @UNC varchar(1000)       exec sp_OACreate 'mpr.WNetGetUniversalName', @objWNet out       exec sp_OAMethod @objWNet, 'WNetGetUniversalName', @UNC out, @Drive       exec sp_OADestroy @objWNet              Print @UNC              But this fails on the first create.              Does anyone know a way to get the UNC path from a mapped drive?              Thanks.              Matthew Wells       matthew.wells@firstbyte.net              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca