Search This Blog

Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Monday, April 22, 2024

pnputil: enable and disable device

The topic of today is how you can work with pnputil.exe to enable and disable devices on your computer.

This was some research and experiments I did to find alternative or complimentary ways to the GUI and PowerShell cmdlets.

By using pnputil.exe /? in PowerShell I found out what some of the uses are and the commands that I was interested in are the following.

To enumerate

This command basically lists all your current devices and their unique ID, in this case it is called Instance ID. Let's say you want to disable a speaker, then you need to find the Instance ID for that speaker.

pnputil /enum-devices

Should you need to enumerate classes for some reason, then this is the command.

pnputil /enum-classes

To disable device

Simply take the full Instance ID for the device, brackets and all.

pnputil /disable-device "SWD\PRINTENUM\{283C1D7C-527C-4D85-8FE7-BCFA6768EA32}"

This example disables Microsoft Print to PDF.

To enable device

It is very much like the previous example, you use the Instance ID to enable the device.

pnputil /enable-device "SWD\PRINTENUM\{283C1D7C-527C-4D85-8FE7-BCFA6768EA32}"

If you keep the device manager open at the same time, you will notice it flicker as the device is enabled/disabled.

Additional examples

You need to run this as an administrator, what you can do for example is to create a simple .ps1 file and then point a shortcut on that file. Then right click the shortcut and run as administrator.

Friday, January 19, 2024

Raspberry Pi 5: Ubuntu server installation

Prerequisites

To get Ubuntu Server on Raspberry Pi it was actually as easy as just getting the Raspberry Pi imager from the official website.

Install it and run it directly.

Choose device (raspberry pi 5), choose OS (other general-purpose OS -> Ubuntu -> Ubuntu Server)

Choose a device to flash it to.

You will have options to include into your file, these are important. You want to set up wifi, make sure SSH is active and set an admin login, this is used later when you SSH in with PowerShell and when you login to the server with RDP. 

Flash the OS to the SD card, you are now done with the first step.

First time booting Ubuntu Server on Raspberry Pi 5

Put the SD card in the device. Keyboard, mouse and monitor is optional as you can manage the device wirelessly and remotely right away if you performed the options detailed in part 1.

Go to your router and find the IP address of the device, this is used in next step.

Open PowerShell and write ssh admin@192.168.0.X where admin is the user name and X is the last part of the IP address. Confirm with password. SSH is a secure alternative to Telnet.

You will then be taken to an admin prompt that takes linux commands.
You might want to start with the following command:

sudo apt-get update && sudo apt-get upgrade

Make sure to confirm if it prompts you.  

GUI and RDP to Ubuntu Server

The last step was to configure a desktop experience and RDP.

For the deskop experience I simply ran two commands, it would seem that the first one is required.

sudo apt install ubuntu-desktop-minimal

sudo apt-get install xfce4

If prompted, I went with the option lightdm and I restarted all serviced that asked me too, some which also disconnected me from the internet.

For the RDP I first ran the following command:

sudo apt install xrdp -y

Followed by this command that shows you if the installation went alright.

sudo systemctl status xrdp

After that I could RDP using the built-in solution on Windows. Some sources claim you need to fix ssl certs and restart the service, but I could start it right away.

Configure your RDP from your Windows computer

Configure a RDP link on your desktop with the following steps:

1. Open remote desktop connection from your start menu

2. Pick "show options"

3. Computer should be the IP address, user name is the one you entered at the flashing of the image

4. Save as, place it in a good location. Now you can use it and just entering your password.

When you login using RDP you will be greeted with a more familiar desktop experience.


Enjoy!

Sunday, December 17, 2023

Windows: Automatic login

Introduction

This post will briefly show how you can set up your Windows device to automatically login upon starting the computer, it works for restarts as well.

It consists of two parts, first part is the GUI way and if that way doesn't work there is registry way.

The necessary security caveat:
Do not add this to a computer that can fall into the hands of the wrong person. It will decrease your device security and it is not encouraged, this post simply illustrates how it can be done.

The GUI way

Start netplwiz from either run or PowerShell.

Right away you will see an option "users must enter a user name and password to use this computer".

Uncheck this, confirm with your password. 

If the option is missing you will have to do the registry way instead.

The registry way

Create a registry file with the following text:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\PasswordLess\Device\]
"DevicePasswordLessBuildVersion"=dword:00000000

After you have saved it as a .reg-file, you can run it and it will make the necessary changes.
You can probably see the option now in step one if you are curious.

Give the computer a restart and it should now automatically log you into the user.


Sunday, December 11, 2022

Windows: Clearing cache, temp files and logs

As a follow up to my previous maintenance post here are a few more advice that will help you clear out some cache primarily, it's not a way to clear much space. You might save up to a gigabyte depending on how long your computer has run without maintenance. Also check out my other post about maintenance.

The script goes as following and can be run by a normal user, it does not force the computer to delete anything that requires admin permissions in other words. So if an admin runs the script it will be even more powerful.

It will clear up logs and temp files, and then also clear the recycling bin. After which it will also clear up some cache.

$ErrorActionPreference = "SilentlyContinue"

Write-Output "Clearing DISM log..."
Get-ChildItem -Path C:\Windows\Logs\DISM | Remove-Item -Recurse

Write-Output "Clearing CBS log..."
Get-Childitem -Path C:\Windows\Logs\CBS | Remove-Item -Recurse

Write-Output "Clearing C:\Windows\Temp"
Get-ChildItem -Path C:\Windows\Temp | Remove-Item -Recurse

Write-Output "Clearing C:\...\AppData\Local\Temp"
$User = $env:username
Get-ChildItem -Path C:\Users\$User\AppData\Local\Temp | Remove-Item -Recurse

Write-Output "Clearing recycle bin"
Clear-RecycleBin -Force

Write-Output "Clearing DNS cache"
Clear-DnsClientCache

Write-Output "Resetting Microsoft Store"
wsreset
Start-Sleep -Milliseconds 700
Stop-Process -name "WinStore.App"

At the end of the script, Microsoft Store will pop up, I've included a line in the script that closes the app again, to leave the user with a more hands off execution.

You can also delete these items manually. For a manual cleanup you can also go to C:\Windows\LiveKernelReports\ and look for big .dmp files. These are dump files and can be investigated in case of a system crash for example. If you have no need to inspect these files you can delete them. I would avoid any folders or other files personally.

Enjoy!

Wednesday, November 16, 2022

Windows: Maintenance and debloating

Keeping your computer clean on the outside is a good thing, equally important is cleaning up the computer internally as well using software. You might simply not want to go through the steps necessary to reinstall the entire computer so here I list some good commands that you can run in PowerShell as an admin. You can also check my other blog post for some tips and tricks on what you can delete to save space.
 

Commands to run in PowerShell

Run system file checker, this sometimes finds and fixes corrupt system files:
SFC /Scannow

Run the tool for Deployment Image Servicing and Management. Basically these are three levels, the last does a bit of repairing. Run SFC before you run any of the DISM commands:
Dism /online /cleanup-image /checkhealth

Dism /online /cleanup-image /scanhealth

Dism /online /cleanup-image /restorehealth

This command can help you recalibrate your system clock. I found it helpful when syncing the clock on computers with a bad battery when internet access have been stopped either by a VPN or because the web browser notices an all too big of a time change. 
Simply run this command to fix the clock:

W32tm /resync /force

In order to fix basic network issues you can run the following commands in this order, the second will disconnect your from the internet usually.

Ipconfig /flushdns

Ipconfig /release

Ipconfig /renew

When changes have been made to the group policy you can try this command to force an update. Pay attention to what settings that override which as well so that you aren't waiting for an update that might not show up.

Gpupdate /force

Running this command let's you check the health of your harddisk.
Chkdsk /f

This command will help you to scan your memory for issues (this command is a program that you can call upon):
mdsched.exe

Some programs to run

Apart from these commands that you can run as admin in the PowerShell window, there are a few built-in programs that you find by searching in your start menu. These are just a good habit to run once in a while to do some cleaning:

Disk cleanup
Disk defragmentation
Storage settings (it will list items you can delete as well)
Full Windows virus scan
 

Debloating script

I've also put together a script that runs through basic pre-installed software and removes it. Sometimes I've tried removing every AppxPackage that I could find, but I found things to get a bit buggy. So this script contains apps that you can live without, all in the name of more resources to what you think is important.

# Run as admin

# Silence errors
$ErrorActionPreference = 'SilentlyContinue';

# App list
$applist = "*3dbuilder*","*windowsalarms*","*windowscommunicationsapps*","*windowscamera*",
"*officehub*","*skypeapp*","*getstarted*","*zunemusic*","*windowsmaps*","*solitairecollection*",
"*bingfinance*","*zunevideo*","*bingnews*","*onenote*","*people*","*bingsports*","*soundrecorder*",
"*bingweather*","*xboxapp*","*xbox*","*Microsoft.MixedReality.Portal*","*GetHelp*","*Microsoft.Messaging*",
"*sketch*","*sticky*","*phone*","*sticky*","*photos*","*calc*","*gethelp*","*camera*"

foreach ($app in $applist) {Get-AppxPackage $app | Remove-AppxPackage}
 
The script works by creating a list where every item is a search word related to apps that can be installed in Windows. If it doesn't find the app it will continue to the next object. When it finds an object it passes it through the pipeline to the removal cmdlet.