Network access

Hi, i need to access a unc directory from my application. The user running the program has access to the domain, but my app is running as a system service and therefore i don't have the network privelages. Is there anyway to give my process access to the domain (using my own username and password for the domain), and not with ImpersonateLoggedOnUser() because i would like it to work even when a user without access to the domain is logged in (using my own uname/pwd).

thanks
deniX23Asked:
Who is Participating?
 
jkrCommented:
>>s there anyway to give my process access to the domain (using my own username and password for the domain)

You could just use 'WNetAddConnection2()' to authenticate to the share, e.g.

    NETRESOURCE         nr;
    DWORD               dwRes;

    ZeroMemory  (   &nr,    sizeof  (   NETRESOURCE));

    nr.dwType           =   RESOURCETYPE_DISK;
    nr.lpLocalName      =   "";
    nr.lpRemoteName     =   "\\\\server\\share";


    dwRes   =   WNetAddConnection2  (   &nr,
                                        "Password",
                                        "UserName",
                                        0
                                    );
0
 
AxterCommented:
Hi deniX23,
> >using my own uname/pwd).
You can change the service option to use your user name and password.

David Maisonave :-)
Cheers!
0
 
deniX23Author Commented:
It's not running on my computer and i can't have it showing my username under "Username" in the task manager (i'd like to have it continue running under SYSTEM).
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
AxterCommented:
The CreateService API function takes the username and password as the last two arguments.
0
 
AxterCommented:
deniX23,
> >It's not running on my computer and i can't have it showing my username
> >under "Username" in the task manager

Why not?

David Maisonave :-}
0
 
deniX23Author Commented:
Thanks!
0
 
jkrCommented:
You're welcome - BTW, don't forget to 'WNetCancelConnection2()' when you're done.
0
 
deniX23Author Commented:
What do i pass as paramater 1 to WNetCancelConnection2()?
Passing what i wrote in nr.lpRemoteName doesnt seem to work, the connection stays open (WNetCancelConnection2 returned 0)
0
 
jkrCommented:
Yes. You need to pass "\\\\server\\share" , as in 'nr.lpRemoteName'.

>>WNetCancelConnection2 returned 0

That means 'NO_ERROR' :o)
0
 
deniX23Author Commented:
I know the return value is ok thats the problem :),
before calling WNetAddConnection2  with "\\\\server\\share" i can't create files there. After calling it i can create files there, but after calling WNetCancelConnection2  with  "\\\\server\\share" i can still create files there... (even if i close and restart the service it continues to have access even without calling AddConnection. only after rebooting does it finally lose access).
0
 
jkrCommented:
Are you setting 'CONNECT_UPDATE_PROFILE' in the flags?
0
 
deniX23Author Commented:
:) Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.