Friday, August 19, 2022

Fix for "The system cannot open the device or file specified" error in Windows Installer

Some time ago I wrote instructions how to increase space on C drive by moving Windows Installer folder C:\Windows\SoftwareDistribution to D drive and creating junction link (see How to free space on OS Windows drive by moving SoftwareDistribution folder to another disk via junction folder). It works but there may be side effects: one of known issue is that after that some (not all) installations from msi files won't work. E.g. I faced with the following error when tried to installed NodeJS:

The system cannot open the device or file specified

 


One solution which you may try is the following:

  1. Remove junction link for C:\Windows\SoftwareDistribution folder (but keep actual folder which contains files on D drive!) and create normal folder C:\Windows\SoftwareDistribution (it will be empty)
  2. Run installer - it should work without errors and should put sub folders of new installation into C:\Windows\SoftwareDistribution
  3. After installation move sub folders from C:\Windows\SoftwareDistribution to SoftwareDistribution on D drive
  4. Delete C:\Windows\SoftwareDistribution folder
  5. Create junction link again

However there is simpler way to avoid mentioned error: run installer in silent mode from PowerShell. I found useful script which does it here. Will post it here in case link won't be available:

$fileName = "..."

$DataStamp = get-date -Format yyyyMMddTHHmmss
$logFile = '{0}-{1}.log' -f $fileName,$DataStamp
$MSIArguments = @(
    "/i"
    ('"{0}"' -f $fileName)
    "/qn"
    "/norestart"
    "/L*v"
    $logFile
)
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow 

Before to run it put full path to your msi file into $fileName variable. Script will run installer in silent mode and will write all steps into log file so you may check results. After that program should appear in the list of installed apps in Control panel > Programs and features.

Wednesday, August 17, 2022

Get Sharepoint data in browser console via Rest API without additional tools

Sometimes during troubleshooting you need to quickly get some data from Sharepoint, e.g. id of current site collection. There are many ways how to do that with additional tools e.g. from PowerShell and PnP, SPEditor Chrome extension and it's pnpjs console, etc. But it requires installation of these tools and their knowledge (of course if you work with Sharepoint it will be better if you will know these tools :) ).

One way how you may get this data without extra tools is to use SP Rest API directly from browser console. E.g. for getting site collection details we may fetch /_api/site endpoint and output JSON response to console:

fetch("https://{mytenant}.sharepoint.com/sites/test/_api/site", {headers: {"accept": "application/json; odata=verbose"}}).then(response => response.json().then(txt => console.log(JSON.stringify(txt))))

(here instead of {mytenant} you should use your tenant name. Note however that this approach will also work in on-prem)

It will output a lot of information about current site collection to the console:

{
    "d": {
        "__metadata": {
            "id": "https://{mytenant}.sharepoint.com/sites/test/_api/site",
            "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site",
            "type": "SP.Site"
        },
        "Audit": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/Audit"
            }
        },
        "CustomScriptSafeDomains": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/CustomScriptSafeDomains"
            }
        },
        "EventReceivers": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/EventReceivers"
            }
        },
        "Features": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/Features"
            }
        },
        "HubSiteSynchronizableVisitorGroup": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/HubSiteSynchronizableVisitorGroup"
            }
        },
        "Owner": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/Owner"
            }
        },
        "RecycleBin": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/RecycleBin"
            }
        },
        "RootWeb": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/RootWeb"
            }
        },
        "SecondaryContact": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/SecondaryContact"
            }
        },
        "UserCustomActions": {
            "__deferred": {
                "uri": "https://{mytenant}.sharepoint.com/sites/test/_api/site/UserCustomActions"
            }
        },
        "AllowCreateDeclarativeWorkflow": false,
        "AllowDesigner": true,
        "AllowMasterPageEditing": false,
        "AllowRevertFromTemplate": false,
        "AllowSaveDeclarativeWorkflowAsTemplate": false,
        "AllowSavePublishDeclarativeWorkflow": false,
        "AllowSelfServiceUpgrade": true,
        "AllowSelfServiceUpgradeEvaluation": true,
        "AuditLogTrimmingRetention": 90,
        "ChannelGroupId": "00000000-0000-0000-0000-000000000000",
        "Classification": "",
        "CompatibilityLevel": 15,
        "CurrentChangeToken": {
            "__metadata": {
                "type": "SP.ChangeToken"
            },
            "StringValue": "..."
        },
        "DisableAppViews": false,
        "DisableCompanyWideSharingLinks": false,
        "DisableFlows": false,
        "ExternalSharingTipsEnabled": false,
        "GeoLocation": "EUR",
        "GroupId": "00000000-0000-0000-0000-000000000000",
        "HubSiteId": "00000000-0000-0000-0000-000000000000",
        "Id": "32d406dc-dc97-46dd-b01c-e6346419ceb7",
        "SensitivityLabelId": null,
        "SensitivityLabel": "00000000-0000-0000-0000-000000000000",
        "IsHubSite": false,
        "LockIssue": null,
        "MaxItemsPerThrottledOperation": 5000,
        "MediaTranscriptionDisabled": false,
        "NeedsB2BUpgrade": false,
        "ResourcePath": {
            "__metadata": {
                "type": "SP.ResourcePath"
            },
            "DecodedUrl": "https://{mytenant}.sharepoint.com/sites/test"
        },
        "PrimaryUri": "https://{mytenant}.sharepoint.com/sites/test",
        "ReadOnly": false,
        "RequiredDesignerVersion": "15.0.0.0",
        "SandboxedCodeActivationCapability": 2,
        "ServerRelativeUrl": "/sites/test",
        "ShareByEmailEnabled": false,
        "ShareByLinkEnabled": false,
        "ShowUrlStructure": false,
        "TrimAuditLog": true,
        "UIVersionConfigurationEnabled": false,
        "UpgradeReminderDate": "1899-12-30T00:00:00",
        "UpgradeScheduled": false,
        "UpgradeScheduledDate": "1753-01-01T00:00:00",
        "Upgrading": false,
        "Url": "https://{mytenant}.sharepoint.com/sites/test",
        "WriteLocked": false
    }
}

sUsing the same approach you may call another Rest API end points directly from browser console. It may save your time during troubleshooting. Hope this information will help someone.

Friday, August 12, 2022

Move C:/Users/{username}/AppData folder to D drive

This article may be useful for those PC owners who has small SSD C drive and needs additional space there without uninstalling apps. Some time ago I wrote an article how to free space on C drive using junction folder links: How to free space on OS Windows drive by moving SoftwareDistribution folder to another disk via junction folder.

Here we will use the same idea but for C:/Users/{username}/AppData folder. In my case WinDirStat showed that most of space is occupied in this folder for my basic user. Moving files from there to D drive included several steps:

1. Create new admin user account and login with this account

2. Go to C:/Users/{username}/AppData for your basic user and rename folder to C:/Users/{username}/AppData.old. If Windows will complain that folder is in use try to use Resource Monitor > CPU > Associated handles tab and search by folder name. It will show all processes which currently use this folder. After that you may kill these processes in Task Manager > Details tab: there is User name column so you may choose those apps which work for your basic user account (and which use files from C:/Users/{username}/AppData).

3. Create new folder on D drive, e.g. D:/UserNameAppData

4. Create junction link using the following command in cmd:

mklink /j C:\Users\{username}\AppData D:\UserNameAppData

5. Move all files from C:/Users/{username}/AppData.old to D:\UserNameAppData

6. Restart PC and login with your basic account

In my case after that Windows start icon stopped working. I tried many instructions to restore it but only the following actually helped: The tale of how I managed to solve a nasty start menu corruption. Will duplicate it here in case this link won't be available:

taskkill /F /IM explorer.exe
taskkill /F /IM SearchApp.exe
taskkill /F /IM SearchUI.exe
taskkill /F /IM ShellExperienceHost.exe
taskkill /F /IM StartMenuExperiencehost.exe
Start-Sleep 2

Set-Location $env:LOCALAPPDATA\Packages\Microsoft.Windows.ShellExperienceHost_cw5n1h2txyewy
Remove-Item -Recurse -Force .\TempState\

Set-Location $env:LOCALAPPDATA\Packages\Microsoft.Windows.StartMenuExperiencehost_cw5n1h2txyewy
Remove-Item -Recurse -Force .\TempState\

Add-AppxPackage -Register "C:\Windows\SystemApps\ShellExperienceHost_cw5n1h2txyewy\AppxManifest.xml" -DisableDevelopmentMode
Add-AppxPackage -Register "C:\Windows\SystemApps\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\AppxManifest.xml" -DisableDevelopmentMode

Start-Process explorer.exe

After that Windows start icon started to work but search in start menu still didn't work. For restoring search in Windows start menu I used another PowerShell command which I found here:

Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}

After that search also started to work. Note that if your D drive is not SSD apps may work slower after this change because files will be physically stored on D drive now. Hope that this information will help someone.