473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Impersonation (change the user) in Windows Application

I need in a Windowsapplication the access to a file that is on a Fileserver.
Only the administrator has access to the directory of the file.
My App needs to open this file. In ASP.net I can Impersonate the user, but
it doesn't work in a Windows App.
I tried to change the Principal of the thread but it doesn't work.
The Script is:

....
Dim LOGON32_LOGON_INTERACTIVE As Integer = 2
Dim LOGON32_LOGON_NETWORK As Integer = 3 'tried both
Dim LOGON32_PROVIDER_DEFAULT As Integer = 0
Dim token As IntPtr
Dim WI As System.Security.Principal.WindowsIdentity
If LogonUser("administrator", "mydom", "password",
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
'Logonuser from API advapi32.dll
WI = New System.Security.Principal.WindowsIdentity(token) 'that works
End If

Dim WP As New System.Security.Principal.WindowsPrincipal(WI) 'that
works
'System.Threading.Thread.CurrentThread.CurrentPrin cipal = WP

Dim NeuerThread As New Threading.Thread(AddressOf newSub)
NeuerThread.CurrentPrincipal = WP 'that works
NeuerThread.Start()
....

' in newSub was tried to get access to that file but it doesn't work

has anybody an idea whats wrong or an solution for this problem?

Thanks a lot Thomas
Nov 21 '05 #1
3 5631
"T. Beneke" <t.******@moehlenhoff.de> schrieb:
I need in a Windowsapplication the access to a file that is on a
Fileserver. Only the administrator has access to the directory of the file.
My App needs to open this file. In ASP.net I can Impersonate the user, but
it doesn't work in a Windows App.


Please don't multipost...

Did you check the solution I posted in the German VB.NET group?

<URL:http://groups.google.de/groups?selm=41384d35%240%2421990%2491cee783%40news reader02.highway.telekom.at>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
Yes I tried your code but it doesn't work at all
Your solution is similar to my first post and other examples on the
internet. An other user told me, that my code work on his environment. I
think I have a problem with the configuration of our Network, Domain or such
like that. The code work in asp.net but it won't work in Win Apps on
computer in our Network (W2003 Fileserver).

I have realy no idea why this code works in other networks but not in our.
:-((

Thomas
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb im Newsbeitrag
news:ei**************@TK2MSFTNGP09.phx.gbl...
"T. Beneke" <t.******@moehlenhoff.de> schrieb:
I need in a Windowsapplication the access to a file that is on a
Fileserver. Only the administrator has access to the directory of the
file.
My App needs to open this file. In ASP.net I can Impersonate the user,
but it doesn't work in a Windows App.


Please don't multipost...

Did you check the solution I posted in the German VB.NET group?

<URL:http://groups.google.de/groups?selm=41384d35%240%2421990%2491cee783%40news reader02.highway.telekom.at>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
I got it.

It worked only with UNC Path but not with mapped drives (S:\temp...)

"T. Beneke" <t.******@moehlenhoff.de> schrieb im Newsbeitrag
news:ul**************@TK2MSFTNGP12.phx.gbl...
Yes I tried your code but it doesn't work at all
Your solution is similar to my first post and other examples on the
internet. An other user told me, that my code work on his environment. I
think I have a problem with the configuration of our Network, Domain or
such like that. The code work in asp.net but it won't work in Win Apps on
computer in our Network (W2003 Fileserver).

I have realy no idea why this code works in other networks but not in our.
:-((

Thomas
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb im
Newsbeitrag news:ei**************@TK2MSFTNGP09.phx.gbl...
"T. Beneke" <t.******@moehlenhoff.de> schrieb:
I need in a Windowsapplication the access to a file that is on a
Fileserver. Only the administrator has access to the directory of the
file.
My App needs to open this file. In ASP.net I can Impersonate the user,
but it doesn't work in a Windows App.


Please don't multipost...

Did you check the solution I posted in the German VB.NET group?

<URL:http://groups.google.de/groups?selm=41384d35%240%2421990%2491cee783%40news reader02.highway.telekom.at>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Louise | last post by:
Hi I have written an HTML pages which does not have any colour specifying tags as far I know. When I view this in an Microsoft internet explorer browser it appears with a white background and...
3
by: Michael | last post by:
Hi, I have a windows service developed using c# and it needs to lunch another windows application. I have been trying to use Process class to do it but the problem is becase windows service...
3
by: Asad | last post by:
Hi, I am trying to write my first Windows application using VB.NET and I am having some difficulties designing the UI. Basically its one Windows Form with 4 menus on the top (no drop downs)....
4
by: Gav | last post by:
Hi, I am writing a windows form application (C#) which access's data from an SQL server. The SQL server is using windows authentication only. At the moment I have to grant the domain users...
0
by: landesjoe | last post by:
Hi, Here's the problem: We have an app that we open by default for the user logged into the Windows box on a Windows Domain (using active directory). Let's say that's "Hans". That works great,...
6
by: Nina | last post by:
Hi Everyone, I have made a windows application using vb.net 2003. When user opens this application it will display a default location in a textbox. This application has to allow user to...
3
by: illegal.prime | last post by:
Hi all, I have a service that needs to start a regular windows application. I'm running the service as ServiceAccount.LocalSystem. But, when it starts the process (using Process.Start) the GUI...
1
by: =?Utf-8?B?Sm9oYW5uIEdyYW5hZG9z?= | last post by:
Hi everybody, Is it possible to do ASP.NET Impersonation in a windows 2003 non domain member server (locate at the DMZ)? If so, how can I do that? Thanks in advance for your kind reply Best...
3
by: DaveL | last post by:
Hi All I have a windows application that needs to run 24/7 in the SysTray How to Start this on Start up When ever the machine is re-started etc I also need to run as a Different User that has...
2
by: loneranger | last post by:
Hi Everyone Visual Studio 2005 VB 2005 Windows Application I have a form with one combo box and a button I want the user to make a selection from the combo box, click the button and have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.