Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows Service - Ability to view Mapped Network Folders

Posted on 2008-06-12
8
Medium Priority
?
359 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 2000 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:Deepu Abraham
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 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