• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

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
0
deniX23
Asked:
deniX23
  • 5
  • 4
  • 3
1 Solution
 
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
 
AxterCommented:
The CreateService API function takes the username and password as the last two arguments.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now