?
Solved

Unable to device as Administrator

Posted on 2010-11-24
4
Medium Priority
?
715 Views
Last Modified: 2012-08-13
I have a weird issue. I have created a program that maps a drive to a folder using DefineDosDevice.  The program works great as a standard user.  I see the folder with the appropriate drive letter.  Once I run the program as an administrator it won;t map the folder.  Here is the function that does the work.

Private Function CreateDevice(DeviceName As String, PathName As String) As String
    If DefineDosDevice(0, DeviceName, PathName) = 0 Then
        MsgBox "Unable to create device " & DeviceName, vbCritical
        CreateDevice = vbNullString
    Else
        CreateDevice = DeviceName
        DoEvents
    End If
End Function

How can I make it work as a standard user and a Administrator.  Thanks.
0
Comment
Question by:elizarrj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 34208093
what is an error?
print out what is err.number and err.description
0
 

Author Comment

by:elizarrj
ID: 34209209
No error is generated. It just does not map the drive when running the program in administor mode.  It does map a drive when run as non administrator.  I did verify that the folder is correct under both scenerios.
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 400 total points
ID: 34209478
that's strange,
you may want to use WMI or net use to map the drive
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 1600 total points
ID: 34209809
You may want to use SetVolumeMountPoint() function instead of DefineDosDevice

SetVolumeMountPoint
http://msdn.microsoft.com/en-us/library/aa365561(v=VS.85).aspx
Option Explicit

Private Declare Function SetVolumeMountPointW Lib "Kernel32.dll" (ByVal lpszVolumeMountPoint As Long, ByVal lpszVolumeName As Long) As Long
Private Declare Function GetVolumeNameForVolumeMountPointW Lib "Kernel32.dll" (ByVal lpszVolumeMountPoint As Long, ByVal lpszVolumeName As Long, ByVal cchBufferLength As Long) As Long


Private Function GetVolumeGuid(ByVal drive As String) As String
    Dim Buffer(128) As Byte
    If GetVolumeNameForVolumeMountPointW(StrPtr(drive), VarPtr(Buffer(0)), 128) Then
        GetVolumeGuid = Left$(Buffer, InStr(Buffer, vbNullChar) - 1)
    Else
        GetVolumeGuid = vbNullString
    End If
End Function

Private Sub Form_Load()
 
    Call SetVolumeMountPointW(StrPtr("c:\test\"), StrPtr(GetVolumeGuid("E:\")))
 
End Sub

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question