How to login to a domain server as admin using

Posted on 2011-05-03
Last Modified: 2012-05-11
Dear Experts,

I have developed an application which is storing ID,Name,FirstName,Photo of an employee, In the Photo field i am storing the address of the picture which is e.g files/pic1.jpg.

Db files is a shared folder in Domain Server to which only the domain admin account has the access. the problem is, when i login from a client computer as admin then i can store,see,delete and update employee pictures on the server. However when other user without admin power logsin then they can't access db files.

my connection string is
        myCon= New SqlConnection("Data Source=;Initial Catalog=abc;User ID=sa;Password=123")

i have a solution but i don't want that, if you give access permission on db files to every one then it is ok, but i don't want that, because irresponsible user then can logs in and can make changes.

Could you tell me that solution or another alternative.
Question by:concern_support
    LVL 57

    Expert Comment

    by:Raja Jegan R
    In that case, Create a Procedure and use WITH EXECUTE_AS clause so that the procedure will always execute it with Admin or Creator privileges.
    Grant permissions on the procedure only to the required users.

    Author Comment

    i don' have any idia. this is my code which copy the picture to the server.

    Where to use the procedure

    Private Sub CopyPic()
                Dim fname, serverpath, CodeNumber As String
                Dim i As Integer
                fname = oOpenFileDialog.FileName()
                If fname <> "" Then
                    i = fname.LastIndexOf("\")
                    substring = fname.Substring(i + 1)
                    Directory.CreateDirectory("\Db files\Picture")
                    File.Copy(fname,"\Db files\Picture" & substring)
                End If
            Catch ex As Exception
            End Try

    Open in new window

    LVL 57

    Expert Comment

    by:Raja Jegan R
    Ok, what I meant is encapsulate all the code used to store images into the share folder using T-SQL code into a procedure and use WITH EXECUTE_AS clause as suggested earlier.
    Seems like you are trying everything using VB scripts.

    Author Comment

    Yes, i am doing it using vb scripts.

    But i don't have any idea of Execute_AS procedure.

    Can you do that code for me using procedure.

    LVL 57

    Expert Comment

    by:Raja Jegan R
    LVL 83

    Accepted Solution

    Given that only path of the picture is being stored in SQL Server, I dont think anything needs to be done in TSQL. What you have to do is use Impersonation in your VB.NET code before accessing the shared folder. With this, you would temporarily act as a domain admin when accessing the server. Its kind of similar to "Run As Administrator". Your users do not need to be given access and they do not need to know the admin password.

    Author Comment

    Yes CodeCruiser i have the same logic, but let me readout the link

    Author Closing Comment


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now