Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: access denied via batch  (Read 18559 times)

0 Members and 1 Guest are viewing this topic.

iONik

    Topic Starter


    Beginner

    access denied via batch
    « on: May 12, 2020, 04:49:52 PM »
    in windows 10...

    Code: [Select]
    @echo off
    cd c:\
    REN 1.hlp 1.txt
    pause

    When executed returns - access is denied, Press any key to continue.
    Why?
    How to fix?

    both the batch file and 1.hlp file are in c:\

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: access denied via batch
    « Reply #1 on: May 13, 2020, 08:49:22 PM »
    Root directory protections. If you place those into a directory within C: such as at C:\Data it will likely work flawless. Everything you got going on should really be elsewhere but root of C: unless it absolutely needs to happen in root of C:

    I think only way to get around the access denied in root of C: is to open the command shell as Administrator which should shut off the access denied issue as its a protection put in place by Microsoft to stop malicious changes from root of C:

    iONik

      Topic Starter


      Beginner

      Re: access denied via batch
      « Reply #2 on: May 18, 2020, 09:23:34 AM »
      It does seem to be a privilege issue, but merely adding a new directory in C does not fix it.
      in other  words...

      Code: [Select]
      @echo off
      cd c:\test
      pause
      ren 1.hlp 1.txt
      does not work for me(bat file and 1.hlp moved to c:\test)
      by changing the permission of the shortcut to "run as admin" results in a prompt to proceed and then it does run.
      I will try this with the full batchfile and report back.

      Hackoo



        Hopeful
      • Thanked: 42
      • Experience: Expert
      • OS: Windows 10
      Re: access denied via batch
      « Reply #3 on: May 18, 2020, 08:06:28 PM »
      Hi ;)
      You should run your batch as administrator to achieve your aim, so try like that instead :
      Code: [Select]
      @echo off
      Title Renaming file
      If [%1] NEQ [Admin] Goto RunAsAdmin
      :MainScript
      cd c:\
      ren 1.hlp 1.txt
      pause
      Exit
      ::---------------------------------------------------------------------------------------------------
      :RunAsAdmin
      cls & color 0B & Mode 90,5
      echo(
      echo(            ===========================================================
      echo(                  Please wait a while ... Running as Admin ....
      echo(            ===========================================================
      Powershell start -verb runas '%0' Admin & Exit
      ::---------------------------------------------------------------------------------------------------

      iONik

        Topic Starter


        Beginner

        Re: access denied via batch
        « Reply #4 on: May 19, 2020, 03:42:33 PM »
        sounds good....will do this!

        iONik

          Topic Starter


          Beginner

          Re: access denied via batch
          « Reply #5 on: May 19, 2020, 05:34:52 PM »
          I'm all good. things are working well. Had to work my way thru all the IF statements that are needed to make sure some unforeseen fault did not occur such as duplicate files, wrong file with wrong name...etc.

          thanks