Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to login to a domain server as admin using vb.net

Posted on 2011-05-03
Medium Priority
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
  • 4
  • 3
LVL 57

Expert Comment

by:Raja Jegan R
ID: 35625313
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

ID: 35633318
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
ID: 35635465
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.
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks


Author Comment

ID: 35637723
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
ID: 35653754
LVL 83

Accepted Solution

CodeCruiser earned 2000 total points
ID: 35688178
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

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

Author Closing Comment

ID: 35688933

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Copy Database Wizard 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.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

580 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