Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4578766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:32:56+00:00 2026-05-21T20:32:56+00:00

I have a windows service and tried to map it using the pinvoke. The

  • 0

I have a windows service and tried to map it using the pinvoke. The code works fine in a console application, but it has no effect in a windows service. According to this:

"net use" command in a Windows Service

I should drop the net use approach and instead give the appropriate privileges, so that my service can access the UNC path ( \server\share\file-path ). How do I set up these privileges? I assume it’s basic Windows privileges that should be set somewhere. Any help is appreciated.

[DllImport("NetApi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern System.UInt32 NetUseAdd(string UncServerName, int Level, ref USE_INFO_2 Buf, out uint ParmError);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct USE_INFO_2
{
    internal LPWSTR ui2_local;
    internal LPWSTR ui2_remote;
    internal LPWSTR ui2_password;
    internal DWORD ui2_status;
    internal DWORD ui2_asg_type;
    internal DWORD ui2_refcount;
    internal DWORD ui2_usecount;
    internal LPWSTR ui2_username;
    internal LPWSTR ui2_domainname;
}

and…

       static void Main()
        {
            USE_INFO_2 useInfo = new USE_INFO_2();
            useInfo.ui2_remote = @"\\xx.xx.xx.xx\E$"; // "\\xx.xx.xx.xx\E$"
            useInfo.ui2_password = "********";
            useInfo.ui2_asg_type = 0;    //disk drive
            useInfo.ui2_usecount = 1;
            useInfo.ui2_username = "Admin";
            useInfo.ui2_domainname = "rendering";
            uint paramErrorIndex;
            uint returnCode = NetUseAdd(String.Empty, 2, ref useInfo, out paramErrorIndex);
            if (returnCode != 0)
            {
                throw new Win32Exception((int)returnCode);
            }
...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:32:57+00:00Added an answer on May 21, 2026 at 8:32 pm

    You could launch your Windows service as a domain/windows user that does have access to this path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows service that runs fine, but I have to have it
I have a Windows service that has been scheduled using Quartz.NET . I have
I have WCF service running from within a Windows Service. This is working fine
I have a windows service written around some code similar to this Asynchronous Server
I have developed a Windows service along with a setup project using Visual Studio
I have a windows service which is using a method from a class library
I have a windows service which is using a method from a class library
I have a windows service application, running under WinXPe, which sometimes fails with an
I have following issue: I'm introducing new feature into application (run as Windows Service)
I am trying to restart Windows Time Service from my asp.net application using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.