Dim fileName As String = "UDOMScreenSaver.scr"
Dim sourceFile As String = Environment.CurrentDirectory & "\" & fileName
Dim destFile As String = Environment.SystemDirectory & "\" & fileName
Try
File.Copy(sourceFile, destFile, True)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Copying files to C:\Windows\system32
Page 1 of 110 Replies - 7125 Views - Last Post: 21 March 2011 - 01:19 PM
#1
Copying files to C:\Windows\system32
Posted 18 March 2011 - 12:58 PM
I am creating a vb.net screen saver setup solution that will copy a .scr file to c:\Windows\system32, but unfortunanetely access denied. It gives error "Acess to path 'C:\Windows\system32\sss.scr' is denied". The code i used are:
Replies To: Copying files to C:\Windows\system32
#2
Re: Copying files to C:\Windows\system32
Posted 18 March 2011 - 01:23 PM
smohd, on 18 March 2011 - 12:58 PM, said:
I am creating a vb.net screen saver setup solution that will copy a .scr file to c:\Windows\system32, but unfortunanetely access denied. It gives error "Acess to path 'C:\Windows\system32\sss.scr' is denied". The code i used are:
Dim fileName As String = "UDOMScreenSaver.scr"
Dim sourceFile As String = Environment.CurrentDirectory & "\" & fileName
Dim destFile As String = Environment.SystemDirectory & "\" & fileName
Try
File.Copy(sourceFile, destFile, True)
Catch ex As Exception
MsgBox(ex.Message)
End Try
First and foremost, in order to access the C:/Windows/System32/ directory you must run the program as an administrator. For the most part, that should rectify your issue. Alternatively, you may want to use File.Create() (I think, check that one) and use a byte[] buffer array of data from the source file. Somewhat like this pseudocode:
Dim fileName As String = "UDOMScreenSaver.scr"
Dim sourceFile As String = Environment.CurrentDirectory & "\" & fileName
Dim bytes as byte[] = File.Read(sourceFile)
Dim destFile As String = Environment.SystemDirectory & "\" & fileName
Try
File.Create(bytes, destFile)
Catch ex As Exception
MsgBox(ex.Message)
End Try
That's not guaranteed to work - CHECK how the methods work in VB - I'm mainly C#
#3
Re: Copying files to C:\Windows\system32
Posted 18 March 2011 - 02:09 PM
but how can i make it to run as admin?
#4
Re: Copying files to C:\Windows\system32
Posted 18 March 2011 - 02:58 PM
I believe you can do this through the project properties dialog, otherwise right-click and 'run as administrator'
#5
Re: Copying files to C:\Windows\system32
Posted 18 March 2011 - 03:38 PM
#6
Re: Copying files to C:\Windows\system32
Posted 18 March 2011 - 03:52 PM
Why you copying files to C:\Windows\system32 any way?
Starting from to day start thinking the user doesn't have admin rights, or can write to any location like XP and Window 98.
- Assume firstly the User is a MS Vista Standard User.
- Treat C:\ as off limits.
- Treat C:\Windows (and it sub directories) as off limits.
In Vista and Windows 7 (32bit versions) the OS can sort "misinform" your application as to where they think there saving and loading from. The 64bit don't have this "lie mechanism" and just crash your application, the think from Microsoft being if your developing for the 64bit version of its OS, I know have to behave correctly.
Starting from to day start thinking the user doesn't have admin rights, or can write to any location like XP and Window 98.
- Assume firstly the User is a MS Vista Standard User.
- Treat C:\ as off limits.
- Treat C:\Windows (and it sub directories) as off limits.
In Vista and Windows 7 (32bit versions) the OS can sort "misinform" your application as to where they think there saving and loading from. The 64bit don't have this "lie mechanism" and just crash your application, the think from Microsoft being if your developing for the 64bit version of its OS, I know have to behave correctly.
#7
Re: Copying files to C:\Windows\system32
Posted 19 March 2011 - 02:16 PM
OK, but I dont understand what u mean! so what should I do?
#8
Re: Copying files to C:\Windows\system32
Posted 20 March 2011 - 10:21 AM
Hello
This is the problem that i too experienced in the past.
So here's its solution.
Go to My Project and click on Windows Settings
There would be something like this:

Replace:
With:
So whenever you will try to run the application, it will ask for adminstrator access.
I think it should solve your problem.
This is the problem that i too experienced in the past.
So here's its solution.
Go to My Project and click on Windows Settings
There would be something like this:

Replace:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
With:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
So whenever you will try to run the application, it will ask for adminstrator access.
I think it should solve your problem.
#9
Re: Copying files to C:\Windows\system32
Posted 20 March 2011 - 01:06 PM
Thanks alot
#10
Re: Copying files to C:\Windows\system32
Posted 20 March 2011 - 01:50 PM
I suggest to not copy a things in Windows/System. You should make your projects to not require Administrator rights. Just a suggestion
#11
Re: Copying files to C:\Windows\system32
Posted 21 March 2011 - 01:19 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|