473,394 Members | 1,829 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,394 software developers and data experts.

Open a file on another domain

I have a file that is residing on a different domain than my program. My
program needs to open up that file. The issue is that I somehow need to
provide the username and password for the domain. How can I do this?

I attached my code so far but this is not working.

Thanks,
Chris
Imports System.Runtime.InteropServices
Imports System.Security.Principal

Public Class Form1

Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal
lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) As Boolean

Public Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal
handle As IntPtr) As Boolean

Const LOGON32_PROVIDER_DEFAULT As Integer = 0
Const LOGON32_LOGON_INTERACTIVE As Integer = 2 ' This is so LogonUser
will create a primary token

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

' Create a token that represents the new user identity
Dim tokenHandle As New IntPtr(0)
tokenHandle = IntPtr.Zero

' Call LogonUser to obtain a handle to an access token.
Dim usr As String = "admin"
Dim pwd As String = "pwd"
Dim dom As String = "webdomain"
Dim returnValue As Boolean = LogonUser(usr, dom, pwd,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, tokenHandle)
If Not returnValue Then
MsgBox("Error # " & Marshal.GetLastWin32Error().ToString)
End
Else
MsgBox("Success")
End If

' Now we use that token to create ourselves a new windows identity
Dim newId As New WindowsIdentity(tokenHandle)

' And temporarily impersonate said user
Dim impersonatedUser As WindowsImpersonationContext =
newId.Impersonate()

Process.Start("\\111.111.11.11\c$\Apps\test.jpg")

' Stop impersonating the user
impersonatedUser.Undo()

' After you're done, good idea to cleanup and free the token
If Not System.IntPtr.op_Equality(tokenHandle, IntPtr.Zero) Then
CloseHandle(tokenHandle)
End If

End Sub

End Class
Jun 27 '08 #1
0 775

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

Similar topics

2
by: Hugo | last post by:
Hi all, Well I don't know if it's possible, but I would like to able to read the content of a html file that I've opened in a new window, but do this from the parent html file. I think that...
1
by: Hardy Wang | last post by:
Hi all: we used to have a development web server in our LAN within same domain. Now we need to build another web development server, but that server is inside its own domain without any trusting....
3
by: Divya | last post by:
Hello, I am trying to copy a file from one domain to another. I have the username and password of the destination domain. I tried a few approaches - 1. Using the Impersonator Class -...
8
by: Lam | last post by:
HI anyone knows how can I open a mapped network file in C#? I try string file = @"T:\file.txt"; it shows me the error: "Could not find a part of the path" but if I copy the file to my C dirve,...
11
by: Andre | last post by:
Hi, I have ASP.NET application running on standalone (not part of the domain) Windows 2003. I use forms authentication for my application. The problem I have is that I need to create and read...
8
by: someone | last post by:
I'm making an program that encodes text, and then writes it into another text file. The problem is that I can't seem to get the "file exists" checking right. If I use the command (coder is the...
4
by: aljamala | last post by:
Hi, I have a link for an employee directory search page. The link (http:// xxxx/Search.aspx) works fine, however, I have another link to do an Advanced Find. and its href is...
5
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.