I created project,
If It Run from Vb.Net program its works fine,
Then Create "Setup" Files and Installed it,
When Run "Exe" file, there is error like this,

From my Project I want to read this file, (Text File)
If I Install this Out of "Program Files" folder, then its works

Please show me, what is my mistake.

try to run as admin,
then al;so it will work...
Check it

the solution is to make your application to start as admin.
(* force start with admin)*
how to force start the application as only admin.?
solution here:

go to solution explorer => go to my project => click view uac settings
your code will look like this:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

change this code to:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

if my suggestion works then please comment me with upvote

Change in code is of one line:

 <requestedExecutionLevel level="asinvoker" uiAccess="false" />
 <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Thank you very much Sir, for your reply,
but there is an error,

ClickOnce does not support the request execution level 'requireAdministrator'

I tried to solve it but couldn't,

Please explain me to correct this,

oh,
Can you send me the project File.
I will not share it to someone but I will send you back with the correction.
you can mail me your project/source folder on my email: modideepkumar@gmail.com

but before this what the error you get?
click details and copy all the text and comment it so if possible then I will help you surely

If you are running your application as admin and working so then your fault is here...
this means your application need admin priveleges...
there one more thing that you can try,
if click once is not allowing you to request as "requireadministrator" the you have to go for coding...
I hope you know the coding to make it run as admin if started without as admin
if no then comment

As to run as Admin you can try this too:

Private Shared Function GetCurrentPrivileges() As Privileges

Form1_Load()
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
'do nothing 
Else
MsgBox("Please run as Admin")
Me.close
End If

Have you get it?
If no then what the error?

If Click-Once is not allowing admin previleges, give this a try. Instead of changing the manifest to run app as admin, add this to the code itself.

 Private Sub RestartElevated()
    Dim startInfo As New ProcessStartInfo()
    startInfo.UseShellExecute = True
    startInfo.WorkingDirectory = Environment.CurrentDirectory
    startInfo.FileName = Application.ExecutablePath
    startInfo.Verb = "runas"
    Try
       Dim p As Process = Process.Start(startInfo)
    Catch ex As System.ComponentModel.Win32Exception
       Return
    End Try

    Application.[Exit]()
 End Sub

This will restart your application with elevated privileges.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.