Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i just make a application simple and there is a exe executive file from bin folder of project i copy and past in another computer for run it some time it is run application and some times shows this error please guide me where is i am missing or any setting
this is vb.net and web form application not as.net

What I have tried:

application attempted to perform an operation not allow by the security policy . to grand this application the required permission contact your system administrator or use the Microsoft framwork configuration tool.
if you are continue the application will ignore this error and attempted to continue if you will quit the application will close immediately .
request registry access is not allowed .

Imports Microsoft.Win32

Public Class Form1
    Public trailtime As DateTime
    Dim VALUE As String
    'Public trailtime As DateTime
    Dim exePath As String = Application.ExecutablePath()
    Dim appPath As String = Application.StartupPath()

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' MsgBox(exePath)
        ' MsgBox(appPath)
        txtapplicationrunpath.Text = appPath + "\file.exe"

        ' Try
        Dim regStarUP As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", True)
        regStarUP.GetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString))
        VALUE = regStarUP.GetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString))
        If Not VALUE = Nothing Then
            If My.Settings.checkbox = True Then
                'Me.WindowState = FormWindowState.Minimized
                ' NotifyIcon1.Icon = SystemIcons.Application
                'NotifyIcon1.BalloonTipText = "thi is minimize"
                'NotifyIcon1.ShowBalloonTip(1000)
                ' Me.ShowInTaskbar = False
                Visible = False
                ShowInTaskbar = False

                ' MyBase.OnLoad(e)
            End If
        Else
            Visible = True
            ShowInTaskbar = True

        End If


        If My.Settings.status = False Then
            'Not My.Settings.check Then
            'My.Settings.check = True
            My.Settings.status = True
            trailtime = DateTime.Now
            My.Settings.expiringdate = Nothing
        Else
            If My.Settings.expiringdate > DateTime.Now Then
                'My.Settings.mydate.Add(New TimeSpan(22, 0, 0, 0)) > DateTime.Now Then
                'MsgBox("active")

            Else

                System.Diagnostics.Process.Start(My.Settings.apppath)
                'MsgBox("exried")
            End If

        End If




        txtremaingdays.Text = My.Settings.expiringdate
        Label2.Text = My.Settings.apppath
        'Label1.Text = Application.ExecutablePath.ToString

        ' Catch ex As Exception

        ' End Try
        

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'OpenFileDialog1.Filter = "EXE FILE|*.EXE|JPEG FILE|*.JPEG|JPG FILE|*.JPG"
        'If OpenFileDialog1.ShowDialog = DialogResult.OK Then
        '    txtapplicationrunpath.Text = OpenFileDialog1.FileName
        'Else
        '    MsgBox("PLEASE SELECT FILE", MsgBoxStyle.Information
        'End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If CheckBox1.Checked = True Then
            My.Settings.checkbox = True
        ElseIf CheckBox1.Checked = False Then
            My.Settings.checkbox = False

        End If

        If txtapplicationrunpath.Text = "" Or TextBox1.Text = "" Then
            MsgBox("Please Browse File Name Not Allow Blank")
        Else
            Dim regStarUP As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", True)
            regStarUP.GetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString))
            VALUE = regStarUP.GetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString))
            If VALUE = Nothing Then
                'If regStarUP.GetValue(Label1.Text) = Nothing Then
                'If VALUE <> Application.ExecutablePath.ToString Then
                regStarUP.SetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString), Application.ExecutablePath.ToString)
                'regStarUP.Close()
                MsgBox("WRITE COMPLETE :")
                My.Settings.apppath = txtapplicationrunpath.Text

            Else

                Dim result = MsgBox("do you want to delete old registry key file ", MsgBoxStyle.YesNo)
                If result = MsgBoxResult.Yes Then
                    regStarUP.DeleteValue(Application.ProductName, True)
                ElseIf result = MsgBoxResult.No Then
                    MsgBox("YOUR OLD FILE IS SAME AS IT WAS THANKS ")

                End If

            End If
            My.Settings.expiringdate = DateTime.Now.AddDays(TextBox1.Text)
        End If
    End Sub

End Class
Posted
Updated 27-Jan-19 9:26am
v3

It looks like your application need administrator, or other, privileges. The solution is to add those privileges, or to remove the offending code (which we cannot see) from your application.
 
Share this answer
 
Comments
irfanansari 27-Jan-19 8:56am    
there is no any way to show you at this place my application sir i am using application with setting.serial key save in this application and then form load then it is see what is serail number in this if is is save then program start other wise ask for serial number
Richard MacCutchan 27-Jan-19 8:58am    
Sorry, but without more information it is impossible even to guess what your application is doing.
irfanansari 27-Jan-19 9:12am    
Imports Microsoft.Win32

Public Class Form1
Public trailtime As DateTime
Dim VALUE As String
'Public trailtime As DateTime
Dim exePath As String = Application.ExecutablePath()
Dim appPath As String = Application.StartupPath()

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' MsgBox(exePath)
' MsgBox(appPath)
txtapplicationrunpath.Text = appPath + "\file.exe"

' Try
Dim regStarUP As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", True)
regStarUP.GetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString))
VALUE = regStarUP.GetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString))
If Not VALUE = Nothing Then
If My.Settings.checkbox = True Then
'Me.WindowState = FormWindowState.Minimized
' NotifyIcon1.Icon = SystemIcons.Application
'NotifyIcon1.BalloonTipText = "thi is minimize"
'NotifyIcon1.ShowBalloonTip(1000)
' Me.ShowInTaskbar = False
Visible = False
ShowInTaskbar = False

' MyBase.OnLoad(e)
End If
Else
Visible = True
ShowInTaskbar = True

End If


If My.Settings.status = False Then
'Not My.Settings.check Then
'My.Settings.check = True
My.Settings.status = True
trailtime = DateTime.Now
My.Settings.expiringdate = Nothing
Else
If My.Settings.expiringdate > DateTime.Now Then
'My.Settings.mydate.Add(New TimeSpan(22, 0, 0, 0)) > DateTime.Now Then
'MsgBox("active")

Else

System.Diagnostics.Process.Start(My.Settings.apppath)
'MsgBox("exried")
End If

End If




txtremaingdays.Text = My.Settings.expiringdate
Label2.Text = My.Settings.apppath
'Label1.Text = Application.ExecutablePath.ToString

' Catch ex As Exception

' End Try


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'OpenFileDialog1.Filter = "EXE FILE|*.EXE|JPEG FILE|*.JPEG|JPG FILE|*.JPG"
'If OpenFileDialog1.ShowDialog = DialogResult.OK Then
' txtapplicationrunpath.Text = OpenFileDialog1.FileName
'Else
' MsgBox("PLEASE SELECT FILE", MsgBoxStyle.Information
'End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If CheckBox1.Checked = True Then
My.Settings.checkbox = True
ElseIf CheckBox1.Checked = False Then
My.Settings.checkbox = False

End If

If txtapplicationrunpath.Text = "" Or TextBox1.Text = "" Then
MsgBox("Please Browse File Name Not Allow Blank")
Else
Dim regStarUP As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", True)
regStarUP.GetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString))
VALUE = regStarUP.GetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString))
If VALUE = Nothing Then
'If regStarUP.GetValue(Label1.Text) = Nothing Then
'If VALUE <> Application.ExecutablePath.ToString Then
regStarUP.SetValue(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString), Application.ExecutablePath.ToString)
'regStarUP.Close()
MsgBox("WRITE COMPLETE :")
My.Settings.apppath = txt
Richard MacCutchan 27-Jan-19 10:32am    
You must run under Administrator privileges in order to modify HKEY_LOCAL_MACHINE registry entries.
irfanansari 28-Jan-19 3:56am    
sir i ask how i can change in my code and what is setting need to be for it
You must add admin privileges to your app. Another solution is move the admin code in a different app which gets started when needed. This has the advantage that the normal app doesnt need to run as admin.

To enable admin rights request you must include some manifest in the project. Read the microsoft documentation for details. Take only the xml from the example and the xml file should have the same case sensitive name as the app.
 
Share this answer
 
Comments
irfanansari 28-Jan-19 3:56am    
sir i ask how i can change in my code and what is setting need to be for it how to setting need to in admin
Everything under HKEY_LOCAL_MACHINE in the registry requires administrator permissions to write to it. Everything under Program Files also requires admin permissions to write to.

If you're trying to turn on/off an option to run your app when a user logs in, you cannot do that as a normal user while trying to write to HKEY_LOCAL_MACHINE. The same registry path exists under HKEY_CURRENT_USER that the user can write to and it will do the exact same thing, but only for that user.
 
Share this answer
 
Comments
irfanansari 28-Jan-19 3:57am    
sir i ask how i can change in my code and what is setting need to be for it
Dave Kreskowiak 28-Jan-19 9:34am    
To do what?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900