Link to home
Start Free TrialLog in
Avatar of Concern Support
Concern SupportFlag for Ireland

asked on

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

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 192.168.0.1/Db 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=192.168.0.1;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.
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

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.
Avatar of Concern Support

ASKER

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

Where to use the procedure

Private Sub CopyPic()
        Try
            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("192.168.0.1\Db files\Picture")
                File.Copy(fname,"192.168.0.1\Db files\Picture" & substring)
                oOpenFileDialog.Reset()
            Else

            End If
        Catch ex As Exception
            GiveError(ex)
        End Try

Open in new window

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.
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.

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes CodeCruiser i have the same logic, but let me readout the link
Great