10 Replies - 12094 Views - Last Post: 21 March 2011 - 01:19 PM Rate Topic: -----

#1 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

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:
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


Is This A Good Question/Topic? 0
  • +

Replies To: Copying files to C:\Windows\system32

#2 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

Re: Copying files to C:\Windows\system32

Posted 18 March 2011 - 01:23 PM

View Postsmohd, 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#
Was This Post Helpful? 1
  • +
  • -

#3 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Copying files to C:\Windows\system32

Posted 18 March 2011 - 02:09 PM

but how can i make it to run as admin?
Was This Post Helpful? 0
  • +
  • -

#4 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

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'
Was This Post Helpful? 1
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Copying files to C:\Windows\system32

Posted 18 March 2011 - 03:38 PM

http://social.answer...0f-a437e07f6728

That topic might be helpful.
Was This Post Helpful? 1
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

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.
Was This Post Helpful? 2
  • +
  • -

#7 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

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?
Was This Post Helpful? 0
  • +
  • -

#8 dreamvb  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 13-March 11

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:
Posted Image
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.
Was This Post Helpful? 1
  • +
  • -

#9 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Copying files to C:\Windows\system32

Posted 20 March 2011 - 01:06 PM

Thanks alot
Was This Post Helpful? 0
  • +
  • -

#10 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

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
Was This Post Helpful? 1
  • +
  • -

#11 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Copying files to C:\Windows\system32

Posted 21 March 2011 - 01:19 PM

View PostNoBrain, on 21 March 2011 - 02:35 AM, said:

I suggest to not copy a things in Windows/System. You should make your projects to not require Administrator rights. Just a suggestion


I accept your suggestion sir
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1