Solved

Windows Service - Ability to view Mapped Network Folders

Posted on 2008-06-12
8
332 Views
Last Modified: 2012-08-14
How can you change the user access privledges of a windows service after it has already started to perform a specific task such as doing a directory listing on a mapped network drive?
0
Comment
Question by:rronec1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 21772445
The problem is that services running under the 'LocalSystem' account have almost OS privileges, but are not allowed to use _any_ networking facilities. To overcome this, make sure to assign your service to run under a predefined user account (preferrably one belonging to the admin group) which does have
network access (this is usually done by specifying an account name&password in the call to 'CreateService()', but you're also able to change this from the 'services' control panel applet). Alternatively, you can also use 'LogonUser()' (http://msdn.microsoft.com/en-us/library/aa378184.aspx) and 'ImpersonateLoggedOnUser()' (http://msdn.microsoft.com/en-us/library/aa378612(VS.85).aspx) at runtime.
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 21776006
You can give a popup dialog for checking the user credentials every time you call the functions to view the Mapped network folders.
have a look at the following link:
http://support.microsoft.com/kb/180548

Best Regards,
DeepuAbrahamK
0
 

Author Comment

by:rronec1
ID: 21794807
Thanks for the helpful feedback. I am able to use the LogonUser and impersonation successfully or at least it's returning from both as true. However, the following logon info doesn't seem to work in my win32 service:

error C2065: 'LOGON32_LOGON_NEW_CREDENTIALS' : undeclared identifier
error C2065: 'LOGON32_PROVIDER_WINNT50' : undeclared identifier

I can only use the following declaration successfully, but yet still unable to copy a file or do a directory listing.

if(domain.length() > 0) // Domain name was specified
bLoggedOn = LogonUser(userName.c_str(),domain.c_str(),password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &userToken_);
else // The following doesn't work!!!!
bLoggedOn = LogonUser(userName.c_str(),domain.c_str(),password.c_str(), LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_WINNT50, &userToken_);

Any thoughts?? Thanks in advance.
0
Technology Partners: 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!

 
LVL 86

Expert Comment

by:jkr
ID: 21795376
Make sure that you have your Windows version set correctly for compiling, i.e.

#define _WIN32_WINNT 0x0500 // W2k and above
#include <windows.h>
//...
0
 

Author Comment

by:rronec1
ID: 21795488
Thanks again. New to this language. When I updated the declaration, it compiled ok for LOGON32_PROVIDER_WINNT50 but same error on LOGON32_LOGON_NEW_CREDENTIALS. Do I need to declare anything else?

Thanks in advance.
0
 
LVL 86

Expert Comment

by:jkr
ID: 21795886
No, nothing that I could think of right now...
0
 

Author Comment

by:rronec1
ID: 21796187
Could this be something with Visual Studio 6.0 that I am using?
0
 
LVL 86

Expert Comment

by:jkr
ID: 21796274
You will need a new Platform SDK if you are using the files that shipped with VC6 - you can get that at http://support.microsoft.com/default.aspx?pr=psdk
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question